一对多的某个情况
<?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="com.qin.repository.ClassesRepository">
<resultMap id="classesMap" type="com.qin.entity.Classes">
<id column="id" property="id"/>
<result column="classname" property="className"/>
<collection property="students" ofType="com.qin.entity.Student" column="s">
<id column="sid" property="id"/>
<result column="sname" property="name"/>
<result column="sage" property="age"/>
</collection>
</resultMap>
<select id="findById" parameterType="int" resultMap="classesMap">
select c.*,s.id as sid,s.name as sname,s.age as sage
from t_class c
join t_student s
on c.id =2 and s.cid =2;
</select>
</mapper>
网友评论