mybatis返回int类型报错 return null from a method with a primitive return type (int).
2017-01-18 10:12
555 查看
SSM 框架,当mybatis返回int类型时,报一下错误:
代码如下:
会报错如下:
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层,代码如下:
代码如下:
会报错如下:
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层,代码如下:
相关文章推荐
- [置顶] 【java】Mybatis返回int类型为空时报错 attempted to return null from a method with a primitive return type (int)
- mybatis -----attempted to return null from a method with a primitive return type (int)
- 关于attempted to return null from a method with a primitive return type (int).报错解决方案
- attempted to return null from a method with a primitive return type (int).
- delete attempted to return null from a method with a primitive return type (int)
- attempted to return null from a method with a primitive return type (int)异常的解决
- MyBatis提示getFundBonus attempted to return null from a method with a primitive return type (double)
- Spring之AOP奇葩报错:Null return value from advice does not match primitive return type for
- mybatis查询,返回类型为resultType,某些属性值为null
- myBatis 返回 int 类型时,报 null 异常
- 如果不空null并且不是空字符串才去修改这个值,但这样写只能针对字符串(String)类型,如果是Integer类型的话就会有问题了。 int i = 0; i!=''。 mybatis中会返回tr
- mybatis查询类型为int的字段,返回null的异常
- mybatis查询类型为int的字段,返回null的异常
- BUG6:Cannot return a value from a method with void result type 返回值错误
- 使用MyBatis查询 返回类型为int,但是当查询结果为空NULL,报异常的解决方法
- aop.AopInvocationException: null return value from advice does not match primitive return type for
- mybatis查询的返回类型为基础类型(int、long等),但结果为null时的异常解决
- mybatis查询类型为int的字段,返回null的异常
- mybatis查询类型为int的字段,返回null的异常
- 当mapper中的parametType为基本类型(如int,string等)时,报错的问题(mybatis使用了<if>判断)