问题描述:
使用单元测试测试sql语句查询时报错:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Statement returned more than one row, where no more than one was expected.
意思是某条sql语句本该查到一条数据,结果返回了多条数据
原因:
检查发现,是dao层的sql语句参数写错了。
解决办法:
修改sql语句
<resultMap id="BaseResultMap" type="cn.itcast.domain.system.Dept">
<id property="id" column="dept_id"/>
<result property="companyName" column="company_name"/>
<result property="deptName" column="dept_name"/>
<result property="state" column="state"/>
<result property="companyId" column="company_id"/>
<association property="parent" column="parent_id"
javaType="cn.itcast.domain.system.Dept" select="findById"/>
</resultMap>
<select id="findAll" resultMap="BaseResultMap">
select * from pe_dept where company_id=#{companyId}
</select>
<select id="findById" resultMap="BaseResultMap">
<!--select * from pe_dept where parent_id=#{id} 这里parent_id修改为dept_id-->
select * from pe_dept where dept_id=#{id}
</select>