mybatis返回int类型报错 return null from a method with a primitive return type (int).

SSM 框架,当mybatis返回int类型时,报一下错误:

mybatis返回int类型报错 return null from a method with a primitive return type (int)._第1张图片

代码如下:

mybatis返回int类型报错 return null from a method with a primitive return type (int)._第2张图片


会报错如下:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Mapper method 'com.jeeplus.modules..res.dao.UserDao.getWeekClass attempted to return null from a method with a primitive return type (int).
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.Java:894)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

解决方案,返回类型设置为封装类型Integer而不是基本类型int

service层如果需要int数据类型,可以自动从Integer进行转换, 当然有可能加入一些判断,比如Integer为Null,赋给int可以先转成0

修改service层,代码如下:

mybatis返回int类型报错 return null from a method with a primitive return type (int)._第3张图片



你可能感兴趣的:(Java,Mybatis)