Statement returned more than one row, where no more than one was expected

<resultMap id="Student" type="org.mybatis.example.Student">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
</resultMap> <resultMap id="InfoResult" type="org.mybatis.example.Student">
<id property="id" column="id" />
<result property="name" column="name" />
<result property="age" column="age" />
<association property="personalInfo" column="id" javaType="org.mybatis.example.PersonalInfo"
select="getPersonalInfo"/>
</resultMap> <select id="getStudentInfo" parameterType="int" resultMap="InfoResult">
select * from student where id &lt; #{id}
</select> <resultMap id="PersonalInfo" type="org.mybatis.example.PersonalInfo">
<id property="id" column="id" />
<result property="height" column="height" />
<result property="weight" column="weight" />
</resultMap> <!-- 选择学生的个人信息 -->
<select id="getPersonalInfo" parameterType="int" resultMap="PersonalInfo">
select * from personal_info where id &lt; #{id}
</select>

下面是测试文件的片段

statement = "org.mybatis.mapping.studentMapper.getStudentInfo";
List<Student> students;
students = session.selectList(statement,2);
System.out.println(students.size());
for(int i=0; i<students.size(); i++) {
System.out.println(students.get(i).toString());

输入2时,返回结果为:

1

Student [name=张三, age=20, id=1, personalInfo=null]

输入3时,返回结果为:

2

Student [name=张三, age=20, id=1, personalInfo=null]

Student [name=李四, age=19, id=2, personalInfo=PersonalInfo [id=1, height=172, weight=67.2]]

输入4时,返回结果为

### Error querying database.  Cause: org.apache.ibatis.executor.ExecutorException: Statement returned more than one row, where no more than one was expected.
### The error may exist in org/mybatis/mapping/studentMapper.xml
### The error may involve org.mybatis.mapping.studentMapper.getPersonalInfo
### The error occurred while handling results
### SQL: select * from personal_info where id < ?

我也是服了网上的这群哥哥们,所有的嵌套查询的例子都是输一个id,然后用`id = #{id}`这种条件来查询的,就没有其他的情况么???

Statement returned more than one row, where no more than one was expected的更多相关文章

  1. mybatis中:returned more than one row, where no more than one was expected.异常

    org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorEx ...

  2. 精尽MyBatis源码分析 - SQL执行过程(四)之延迟加载

    该系列文档是本人在学习 Mybatis 的源码过程中总结下来的,可能对读者不太友好,请结合我的源码注释(Mybatis源码分析 GitHub 地址.Mybatis-Spring 源码分析 GitHub ...

  3. MyBatis关联查询和懒加载错误

    MyBatis关联查询和懒加载错误 今天在写项目时遇到了个BUG.先说一下背景,前端请求更新生产订单状态,后端从前端接收到生产订单ID进行查询,然后就有问题了. 先看控制台报错: org.apache ...

  4. The command 'new_value' for SQLPlus

    Format: column column_name new_value var_name Meaning: use the column_name of a select statment to c ...

  5. ERROR 1666 (HY000): Cannot execute statement: impossible to write to binary log since statement is in row format and BINLOG_FORMAT = STATEMENT.

    centos7.5 binlog恢复数据失败 问题: mysql> \. /tmp/inc.sql ERROR 1050 (42S01): Table 'new_1' already exist ...

  6. MySQL binlog_format (Mixed,Statement,Row)[转]

    MySQL 5.5 中对于二进制日志 (binlog) 有 3 种不同的格式可选:Mixed,Statement,Row,默认格式是 Statement.总结一下这三种格式日志的优缺点. MySQL ...

  7. 直接放个DB2 SQL STATEMENT大全好了!

    SQL statements   This topic contains tables that list the SQL statements classified by type. SQL sch ...

  8. The Secrets of Oracle Row Chaining and Migration

    from http://www.akadia.com/services/ora_chained_rows.html Overview If you notice poor performance in ...

  9. BINARY SEARCH in read table statement

    1.for standard table, it must be sorted by search key. 2.for sorted table , binary search is used au ...

随机推荐

  1. IOS第七天(3:UiTableView 模型和数据的分组的显示)

    *************UiTableView模型和数据的分组的显示 #import "HMViewController.h" #import "HMHero.h&qu ...

  2. Eclipse创建java web工程配置Tomacat和JDK 【转】

    在学习AJAX过程中,还用Intellij就有点老旧了,这是后装个Eclipse时,发现这个配置也很头疼,现在就叫你如何创建一个web工程,同时叫你配置Eclipse. 一.创建一个web工程 1.打 ...

  3. mac os x 连不上android 手机

    在系统关于中查询mac的usb的厂商ID 如id为0x2717 执行echo 0x2717 >> ~/.android/adb_usb.ini 即可

  4. 【译】在ASP.Net和IIS中删除不必要的HTTP响应头

    引入 每次当浏览器向Web服务器发起一个请求的时,都会伴随着一些HTTP头的发送.而这些HTTP头是用于给Web服务器提供一些额外信息以便于处理请求.比如说吧.如果浏览器支持压缩功能,则浏览器会发送A ...

  5. ConcurrentHashMap Put()操作示例代码

    非常简练: private static void put(MetricKey key, float value) { MetricValue current; do { current = map. ...

  6. Linux系统下Redis安装(二)

    上一篇随笔,已经成功开启了Redis-server,客户端已经可以正常对redis进行正常操作. 但是,redis-server开启的同时,一个大大doc黑屏也在那里开启着,接下来就对讲解如何在Lin ...

  7. spring记录

    context:property-placeholder 是将properties加载到Spring上下文中,接下来在定义bean的时候就能用${xx.xx}来访问了. util:properties ...

  8. [Android Tips] 9. framework notification layout font size

    android 4.4 framework notification layout 相关字体大小 * title: notification_title_text_size: 18dp * conte ...

  9. [Android Tips] 1. Getting StatusBar Height

    public int getStatusBarHeight() { int result = 0; int resourceId = getResources().getIdentifier(&quo ...

  10. linux----------CentOS的一些命令记录。

    1.查看linux操作系统位数的命令:getconf LONG_BIT 2.安装sz(下载)和rz(上传)命令:yum install lrzsz 3.tail -n 5 文件名字    : 查看大型 ...