1.新建学生和状态类
状态类的主键是学生的熟悉
2.配置info1.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="zjhsxl">
<resultMap id="info1Map" type="com.pro.domain.Info1">
<id property="stu.stuId" column="stuId"/>
<result property="stu.stuName" column="stuName"/>
<result property="stu.sex" column="sex"/>
<result property="status.statusId" column="statusId"/>
<result property="status.status" column="status"/>
</resultMap>
<select id="selectInfo1" resultMap="info1Map">
select s.*,s1.* from Student s,status s1 where s.statusId=s1.statusId
</select>
</mapper>
3.batis.xml添加索引
<mapper resource="info1.xml"/>
4.测试类添加测试方法
显示出两张表的内容
@Test
public void testSelectInfo1() throws IOException {
List<Info1> infoList = sqlSession.selectList("zjhsxl.selectInfo1");
for(Info1 info: infoList){
System.out.println(info.getStu().getStuName()+","+info.getStatus().getStatus());
}
sqlSession.commit();
System.out.println(infoList.size());
}