Expected one result (or null) to be returned by selectOne() 数据库结果集和java实例
mybatis会根据查询的结果集初始化java实例。
如果是复杂类型,我们一般都会在mapper中做好映射。
1.所以如果查询到的是多个结果,那么对应的java类型也必须的集合类型。(result 为泛型或者集合元素类型,dao接口必须为集合)
如: xml:<select id='xx' resultType='java.lang.String'> 接口:String[] xx();
2.但是有一种,结果集虽然是多个,但是需要是一个实例。
如:查询班级及学生 SELECT * FROM clazz LEFT JOIN student on。。。。
我们对应java实例就是clazz即{ clazzName, student[] }。
所以这条语句,只要不是只有一个学生那么肯定会有多条结果。但是我们需要mybatis为我们创建一个实例。
这个也就是 resultMap,resultType 的区别。resultMap 是我们做好映射关系的,里面有collection属性,所以mybatis会为我们创建一个实例。
如果使用resultType ,mybatis就会说:Expected one result (or null) to be returned by selectOne() 。查出来好几个,你就要一个,要哪个啊?
所以,出现这个问题 Expected one result (or null) to be returned by selectOne()。第一是产生多个结果,我们也要多个,但是接收类型写错了。第二就是产生多个,但是我们需要一个,(因为多个结果其实对java是一个实例)那么就是映射没有做好,或者使用了resultType,而不是resultMap。
Expected one result (or null) to be returned by selectOne() 数据库结果集和java实例的更多相关文章
- Caused by: org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2
异常信息 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with na ...
- Expected one result (or null) to be returned by selectOne(), but found: 3
Expected one result (or null) to be returned by selectOne(), but found: 3 返回应该是对象但是给的是list
- Expected one result (or null) to be returned by selectOne(), but found: 2 和 java.lang.UnsupportedOperationException异常
在学习MyBatis的时候,简简单单的MyBatis+MySql的增删改查操作,但是却出了问题. 刚开始数据库只有一条数据的时候,岁月静好,一切看起来都那么的OJBK.但是,当我往数据库插入第二条数据 ...
- 测试环境部署之填坑记录-Expected one result (or null) to be returned by selectOne(), but found: 2
最近在部署性能测试环境的时候,环境 部署好以后,部分功能出现接口查询异常,问题现象: 拿到错误,肯定要先判断是前端还是后端代码的问题,最简单的方式是抓包查看: 以上是报错页面捕获的接口报错,很明显的接 ...
- org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 3报错解决
报错的原因翻译出来: 预期的一个结果(或null)返回selectOne(),但发现:3 意思就是你想得到一个结果值,但是返回了三个结果值. 一般可能测试的时候我们存了几条一样的数据,在登录时,会把同 ...
- Expected one result (or null) to be returned by selectOne(), but found 2
这个问题在于你查询sql返回结果是多个值.一个集合,但是你在service的实现层的dao都调用了.get方法.而是应该使用.getlist方法等.
- 【java异常】Expected one result (or null) to be returned by selectOne(), but found: 63
OmQuotaTBBean omQuotaTBBean = mOmQuotaTBMapper.findOmQuotaTB(); 改成 List<OmQuotaTBBean> listOmQ ...
- 一个坑:java.sql.ResultSet.getInt==》the column value; if the value is SQL NULL, the value returned is 0
Retrieves the value of the designated column in the current row of this ResultSet object as a String ...
- Linux下启动tomcat报错,WARN org.apache.zookeeper.ClientCnxn - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect java.net.ConnectException:
tomcat启动完了之后,一直不停的打印这种错误信息,看表面上,应该是zk节点下的数据是空的,连接不上服务,所以一直在尝试连接,然后一直又连不上: 完整的错误信息: 407662 [usf-ZooKe ...
随机推荐
- WinForm:如何在ListBox中添加CheckBox
http://www.cnblogs.com/myshell/archive/2010/09/24/1834184.html 最近因为做WinForm的项目,遇到这个问题,当时以为CheckedLis ...
- 二gradle创建SSM项目——Hello word
一创建gradle web项目 1.以下是我的项目结构web工程+工具module,mapper用来存放mybatis-plus自动生成类,通过 MpGenerator.class 生成. 项目结 ...
- Tree命令安装和使用
Tree命令简介 tree是一种递归目录列表命令,产生一个深度缩进列表文件,这是彩色的ALA dircolors如果ls_colors设置环境变量和输出是TTY.树已经被移植和报道以下操作系统下工作: ...
- oralce 汇编02
Assembler Directives .align integer, padThe .align directive causes the next data generated to be al ...
- 10 | MySQL为什么有时候会选错索引? 学习记录
<MySQL实战45讲>10 | MySQL为什么有时候会选错索引? 学习记录http://naotu.baidu.com/file/e7c521276650e80fe24584bc9a6 ...
- pycharm安装第三方库失败module 'pip' has no attribute 'main'
用的pycharm2017.3,新创建一个项目,在安装appium-python-client时报错module 'pip' has no attribute 'main'.通过强大的度娘,知道是pi ...
- 记录ViewPager配合Fragment使用中遇到的一个问题
java.lang.IllegalStateException: FragmentManager is already executing transactions 如图所示: 当调用 notifyD ...
- 1349 - View's SELECT contains a subquery in the FROM clause
mysql创建视图 报错1349 - View's SELECT contains a subquery in the FROM clause:: 原因创建视图的sql语句中有不支持子查询, 所以需要 ...
- 饿了么CTO张雪峰:允许90后的技术人员“浮躁“一点
编者按:今年4月,饿了么正式加入了阿里新零售战队,进一步加速其在本地生活市场的扩张速度.在创业9年的时间中,饿了么在外卖领域经历了真正的“从0到1”,尤其是在外卖平台的技术升级方面,越过了一个又一个的 ...
- php strspn()函数 语法
php strspn()函数 语法 作用:返回字符串中包含某些字符的数目.大理石平台厂家 语法:strspn(string,charlist,start,length) 参数: 参数 描述 strin ...