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)

1.场景:

根据Post请求接收参数,准备查询mysql中某条数据时报错。
  1. 期望:查询到该条数据的具体id,并且返回该条数据的id
  2. 实际:mysql表中根本没有此条数据,所以查询结果为null

2.原因:

出错在:企图使int id = null;成立
因为未查询到,所以方法返回null;但是在.xml中,却采用了int类型作为返回值

<select id="xxx" parameterType="xxx" resultType="int">

3.解决

  1. <select resultType="java.lang.Integer">
  2. Service中或者Biz中,方法的返回值也为 :Integer即可

猜你喜欢

转载自blog.csdn.net/tmax52HZ/article/details/107017709