Mybatis返回值类型

 
  1. 第一种:resultType为基本类型,如string(在此暂且把string归纳为基本类型) 如果select的结果为空,则dao接口返回结果为null
  1. 第二种:resultType为基本类型,如int 后台报异常: org.apache.ibatis.binding.BindingException: Mapper method 'com.fkit.dao.xxDao.getUserById attempted to return null from a method with a primitive return type (int). 解释:查询结果为null,试图返回null但是方法定义的返回值是int,null转为int时报错 解决办法:修改select的返回值为String
  1. 第三种: resultType为类为map ,如map、hashmap dao层接口返回值为null
  1. 第四种: resultType 为list ,如list dao层接口返回值为[],即空集合。 注意:此时判断查询是否为空就不能用null做判断
  1. 第五种: resultType 为类 ,如com.fkit.pojo.User dao层接口返回值null
所以为了健壮性,在mybatis中,除了统计数据,不要用基本类型来接收结果,最好都用包装类型。
Loading...
目录
文章列表
王小扬博客
云原生
Git
Elasticsearch
Apollo
产品
Think
生活技巧
软件开发
计算机网络
CI
DB
设计
缓存
Docker
Node
操作系统
Java
大前端
Nestjs
其他
PHP
AI