mybatis 级联的两种形式
来源:互联网 发布:两年经验的程序员工资 编辑:程序博客网 时间:2024/06/13 22:59
<?xmlversion="1.0"encoding="utf8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mappernamespace="com.abc.mapper.StudentMapper">
<selectid="getById"parameterType="int"resultMap="studentResultMap">
select s.id s_id,
s.name s_name,
s.gender s_gender,
s.major s_major,
s.grade s_grade,
t.id t_id,
t.name t_name,
t.gender t_gender,
t.title t_title,
t.research_area t_research_area
from student s left join teacher t
on s.supervisor_id = t.id
where s.id=#{id}
</select>
<resultMapid="studentResultMap"type="Student">
<idproperty="id"column="s_id"/>
<resultproperty="name"column="s_name"/>
<resultproperty="gender"column="s_gender"/>
<resultproperty="major"column="s_major"/>
<resultproperty="grade"column="s_grade"/>
<!--使用resultMap属性引用下面的教师实体映射-->
<associationproperty="supervisor"javaType="Teacher"
resultMap="supervisorResultMap"/>
</resultMap>
<!--教师实体映射-->
<resultMapid="supervisorResultMap"type="Teacher">
<idproperty="id"column="t_id"/>
<resultproperty="name"column="t_name"/>
<resultproperty="gender"column="t_gender"/>
<resultproperty="researchArea"column="t_research_area"/>
<resultproperty="title"column="t_title"/>
</resultMap>
</mapper>
<?xmlversion="1.0"encoding="utf8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mappernamespace="com.abc.mapper.StudentMapper">
<selectid="getById"parameterType="int"resultMap="studentResultMap">
select id,name,gender,major,grade,supervisor_id from student where id=#{id}
</select>
<selectid="selectSupervisor"parameterType="int"resultMap="supervisorResultMap">
select id,name,gender,title,research_area
from teacher where id=#{id}
</select>
<resultMapid="studentResultMap"type="Student">
<idproperty="id"column="id"/>
<resultproperty="name"column="name"/>
<resultproperty="gender"column="gender"/>
<resultproperty="major"column="major"/>
<resultproperty="grade"column="grade"/>
<!--column="supervisor_id"不能少。此列的值作为参数
传递给要引用的select语句,用来查询相应学生的指导教师
的信息。select属性指定要引用的select语句-->
<associationproperty="supervisor"javaType="Teacher"
column="supervisor_id"select="selectSupervisor"/>
</resultMap>
<!--教师实体映射-->
<resultMapid="supervisorResultMap"type="Teacher">
<idproperty="id"column="id"/>
<resultproperty="name"column="name"/>
<resultproperty="gender"column="gender"/>
<resultproperty="researchArea"column="research_area"/>
<resultproperty="title"column="title"/>
</resultMap>
</mapper>
- mybatis 级联的两种形式
- mybatis association的两种形式
- MyBatis的级联查询(两种方式)
- MyBatis的association示例以及association的两种形式
- MyBatis association的两种形式——MyBatis学习笔记之四
- UIActivityIndicatorView的两种形式
- UIActivityIndicatorView的两种形式
- UIActivityIndicatorView的两种形式
- UIActivityIndicatorView的两种形式
- UIActivityIndicatorView的两种形式
- split 的两种形式
- UIActivityIndicatorView的两种形式
- #include的两种形式
- UIActivityIndicatorView的两种形式
- UIActivityIndicatorView的两种形式
- UIActivityIndicatorView的两种形式
- alert 的两种形式
- 运动的两种形式
- phpword生成word文档
- 3. 数组
- 22 - Remove Duplicates from Sorted Array
- 23 - Remove Element
- mybatis N+1问题
- mybatis 级联的两种形式
- check cable connection PXE-M0F: Exiting intel PXE ROM no bootable device-- insert boot disk and pre
- 24 - Implement strStr()
- VDS Best Practices – Design Considerations (Part 1 of 6)
- mybatis 泛型DAO接口设计
- VDS Best Practices – Virtual and Physical Switch Parameters (Part 2 of 6)
- s3c2440裸板(一)--存储控制器
- VDS Best Practices – Rack Server Deployment with Eight 1 Gigabit adapters (Part 3 of 6)
- CRC校验