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

异常的原因:需要一个或空参数,但是返回了3个参数。我的两张表是t_article和t_comment,其中t_article一个属性是包含t_comment,如List commentList,所以Article类的commentList是可以接受多个Comment实体类参数的,这里是映射没弄好,导致多个参数映射不到commentList里面,下面开始解决。
最近用springboot整合Mybatis,之前一直用注解方式整合,太久没有用过mybatis的xml配置文件方式整合,导致配置出现异常,主要是忘了mybatis的cloumn属性,如下图

红圈的地方主要是圈cloumn属性的值,因为cloumn属性的值不能带.号,所以只能给多表的字段起别名,比如 c.id [as] c_id,最好起别名,因为如果多表连接时,如果其中多表的字段名相同,那么就可能不知道映射的是哪张表的字段。如下图

the end.

原文地址:https://www.cnblogs.com/unlasting/p/15477216.html