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. [转]从网页Web上调用本地应用程序(.jar、.exe)的主流处理方法

    这个方法主要思路是利用自定义URL Protocol来调用应用程序.浏览器在解析到自定义URL Protocol之后,会寻找注册表,然后通过注册表启动相应的程序,然后启动改程序,传入参数.对于我这个项 ...

  2. Graph | Eulerian path

    In graph theory, a Eulerian trail (or Eulerian path) is a trail in a graph which visits every edge e ...

  3. 剑指offer?

    1. 在一个m*n二维数组中,每一行都按照从左到右的递增顺排序,每一列都按照从上到下的顺序排序,请完成一个函数,输入这样一个二维数组和一个整数,判断数组中是否含有该整数.1 2 8 92 4 9 12 ...

  4. JS写的CRC16校验算法(查表法)

    var CRC = {}; CRC._auchCRCHi = [ 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0 ...

  5. ThinkPHP 3.2.3 简单后台模块开发(一)常用配置

    一.项目分组 下载解压 ThinkPHP 3.2.3,在默认的应用 Application(./Application) 中,包含一个默认的模块 Home(./Application/Home). 需 ...

  6. nginx https ssl 设置受信任证书[原创]

    1. 安装nginx 支持ssl模块 http://nginx.org/en/docs/configure.html yum -y install openssh openssh-devel (htt ...

  7. 转载:GridControl使用技巧

    一.如何解决单击记录整行选中的问题 View->OptionsBehavior->EditorShowMode 设置为:Click 二.如何新增一条记录 (1).gridView.AddN ...

  8. Android 签名比较

    一. keytool -list -printcert -jarfile "%filename%" 二. 非常low方法:下载的应用安装能成功覆盖原应用则签名一致三. 作者:陈子腾 ...

  9. CCEA OCX

    <HTML> <HEAD> <TITLE>CCEAActiveX演示页面</TITLE> <meta http-equiv="Conte ...

  10. Git reset 常见用法

    Git reset 1. 文件从暂存区回退到工作区 2. 版本回退 1.1 git reset HEAD filename :回退文件,将文件从暂存区回退到工作区 //也可以使用 git reset ...