首页 新闻 会员 周边 捐助

paramenterType="java.util.Map" map里面的值,传不到MySQL语句里

0
悬赏园豆:10 [待解决问题]

A.使用工具IDEA

B.MySQL数据库 

C.Maven JavaWeb项目

——————————————————————

问题:

  map里面的值传不到 user1Mapper.xml 的 MySQL 语句里

发送的SQL语句为null

18:31:58,446 DEBUG loginFind:145 - ==>  Preparing: SELECT * FROM user WHERE loginname=? and password=? 
18:31:58,493 DEBUG loginFind:145 - ==> Parameters: null, null
18:31:58,514 DEBUG loginFind:145 - <==      Total: 0

 

————————

报错:内容

java.lang.NullPointerException
at com.dunef.service.User1ServiceImp.loginFind(User1ServiceImp.java:31)
at com.dunef.controller.User1Controller.findLogin(User1Controller.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:625)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:498)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:796)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1372)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

--------------------------------------------

1定义了一个entity类,已经有set,get,方法

public class User1 {
    private String loginname;
    private String password;

2,mapper层

public interface User1Mapper {
    User1 loginFind(Map<String,String>map);
}

3 ,mapper.xml代码

<mapper namespace="com.dunef.mapper.User1Mapper">
    <select id="loginFind" parameterType="java.util.Map" resultType="com.dunef.entity.User1">
        SELECT
         *
     FROM
        user WHERE    loginname=#{loginname} and password=#{password}
</select> </mapper>

4 , service 接口层

public interface User1Service {
    User1 loginFind(String loginname,String password);
}

5, service 实现类

   @Service
  public class User1ServiceImp implements User1Service{
  @Resource
private User1Mapper user1Mapper; private HashMap<String, String> map; private User1 user2;

@Override public User1 loginFind(String loginname, String password) { map = new HashMap<>(); map.put(loginname, loginname); map.put(password, password); user2 = user1Mapper.loginFind(map);//31行,这句返回值为空,数据库,map值传不进去
      System.out.println(user2);
return user2; } }

6,controller层,设置了数据库里的一条信息

复制代码
@Controller
public class User1Controller {
    @Resource
    private User1Service user1Service;
    @RequestMapping("/find")
    public void findLogin(){
        user1Service.loginFind("c","c");
    }
复制代码
dune.F的主页 dune.F | 初学一级 | 园豆:198
提问于:2017-10-26 17:11
< >
分享
所有回答(1)
0

解决方案:

5, service 实现类

在此处map的key值,添加双引号。

map.put(loginname, loginname);

map.put(password, password);

-------------------------------------------------

改变后的代码为:

map.put(“loginname”, loginname); 

map.put(“password”, password);

————————————————————————————————

不知道为什么,

String stringCode = request.getParamenter("前端字符串");

在别的电脑上map.put时候设置stringCode为key不加引号,可以实现MySQL传值。
parameterType="java.util.Map"

在我的电脑xml里的SQL语句,idea,eclipse都不识别map的key(也算事极个别情况)

dune.F | 园豆:198 (初学一级) | 2017-10-27 08:29
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册