attempted to return null from a method with a primitive return type (int)
1.场景:
根据Post请求接收参数,准备查询mysql中某条数据时报错。
- 期望:查询到该条数据的具体id,并且返回该条数据的id
- 实际:mysql表中根本没有此条数据,所以查询结果为null
2.原因:
出错在:企图使int id = null;
成立
因为未查询到,所以方法返回null;但是在.xml中,却采用了int类型作为返回值
<select id="xxx" parameterType="xxx" resultType="int">
3.解决
<select resultType="java.lang.Integer">
- Service中或者Biz中,方法的返回值也为 :Integer即可