在使用mybatis 的时候发现类似是下标越界的错误
这是Emp类
@Data
@Builder
public class Emp {
Integer id;
String name;
String sex;
Integer deptno;
Date hiredate;
Dept dept;
}
这是dept类
@Data
@Builder
public class Dept {
Integer id;
String name;
List<Emp> empList;
}
查询
<select id="selectAll" resultMap="MyEmpMapper">
select * from sys_emp
</select>
<resultMap id="MyEmpMapper" type="Emp">
<id column="id" property="id"></id>
<result column="name" property="name"></result>
<result column="sex" property="sex"></result>
<result column="deptno" property="deptno"></result>
<result column="hiredate" property="hiredate"></result>
<association property="dept" javaType="com.entity.Dept" column="deptno" select="selectDeptByNo">
</association>
</resultMap>
<resultMap id="MyDept" type="Dept">
<result property="id" column="deptno"></result>
<result property="name" column="dname"></result>
</resultMap>
<select id="selectDeptByNo" resultType="Dept" resultMap="MyDept">
select * from sys_dept where deptno = #{deptno}
</select>
这个很奇怪啊,我昨天测试的时候是正确的,但是今天测试,发现了这个问题,结果上网一搜发现是说要加无参构造方法,我加了,后面也成功了,所以就很疑惑,我昨天明显test成功了,为什么今天就不行呢?