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实例的更多相关文章

  1. 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 ...

  2. 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

  3. Expected one result (or null) to be returned by selectOne(), but found: 2 和 java.lang.UnsupportedOperationException异常

    在学习MyBatis的时候,简简单单的MyBatis+MySql的增删改查操作,但是却出了问题. 刚开始数据库只有一条数据的时候,岁月静好,一切看起来都那么的OJBK.但是,当我往数据库插入第二条数据 ...

  4. 测试环境部署之填坑记录-Expected one result (or null) to be returned by selectOne(), but found: 2

    最近在部署性能测试环境的时候,环境 部署好以后,部分功能出现接口查询异常,问题现象: 拿到错误,肯定要先判断是前端还是后端代码的问题,最简单的方式是抓包查看: 以上是报错页面捕获的接口报错,很明显的接 ...

  5. 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 意思就是你想得到一个结果值,但是返回了三个结果值. 一般可能测试的时候我们存了几条一样的数据,在登录时,会把同 ...

  6. Expected one result (or null) to be returned by selectOne(), but found 2

    这个问题在于你查询sql返回结果是多个值.一个集合,但是你在service的实现层的dao都调用了.get方法.而是应该使用.getlist方法等.

  7. 【java异常】Expected one result (or null) to be returned by selectOne(), but found: 63

    OmQuotaTBBean omQuotaTBBean = mOmQuotaTBMapper.findOmQuotaTB(); 改成 List<OmQuotaTBBean> listOmQ ...

  8. 一个坑: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 ...

  9. 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 ...

随机推荐

  1. Python之路-Python中的线程与进程

    一.发展背景 任务调度 大部分操作系统(如Windows.Linux)的任务调度是采用时间片轮转的抢占式调度方式,也就是说一个任务执行一小段时间后强制暂停去执行下一个任务,每个任务轮流执行.任务执行的 ...

  2. vue项目上传到OSS

    1.输入阿里云登陆地址 http://signin.aliyun.com/1987179281335458/login.htm 登陆地址 阿里云账号    2.选择对象oss,建议文件夹   3.将文 ...

  3. c# 读取二进制文件并转换为 16 进制显示

    string result = ""; string filePath = "xxx.bin"; if (File.Exists(filePath)) { by ...

  4. linux清理 clientmqueue 垃圾文件防止 inode 被占满

    #find /var/spool/clientmqueue/ -type -f |xargs rm -f

  5. 洛谷 P2783 有机化学之神偶尔会做作弊(Tarjan,LCA)

    题目背景 LS中学化学竞赛组教练是一个酷爱炉石的人. 有一天他一边搓炉石一边监考,而你作为一个信息竞赛的大神也来凑热闹. 然而你的化竞基友却向你求助了. “第1354题怎么做”<--手语 他问道 ...

  6. bzoj3809 Gty的二逼妹子序列 & bzoj3236 [Ahoi2013]作业 莫队+分块

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=3809 https://lydsy.com/JudgeOnline/problem.php?id ...

  7. Python---编辑器安装和print函数

    Python---编辑器安装和print函数 -------------------------------------------------------- 一.Python是什么? Python是 ...

  8. Task2.特征提取

    参考:https://blog.csdn.net/u012052268/article/details/77825981/ 利用jieba分词工具去除停用词: 停用词:1.在SEO中为节省空间和提高搜 ...

  9. python线程池示例

    使用with方式创建线程池,任务执行完毕之后,会自动关闭资源 , 否则就需要手动关闭线程池资源  import threading, time from concurrent.futures impo ...

  10. python学习笔记(十三)处理时间模块

    import time time.sleep(2)#等待几秒 时间的三种表现方式: 1.格式化好的时间 2018-1-14 16:12 2.时间戳 是从unix元年到现在所有的秒数 3.时间元组 想时 ...