-
mybatis 一对一关联对象查询
- <select id="getClassInfo" parameterType="int" resultMap="ClassResultMap">
- select * from class c,teacher t where c.teacher_id = t.t_id and c.c_id = #{id}
- </select>
-
- <resultMap type="Classes" id="ClassResultMap">
- <id property="id" column="c_id"/>
- <result property="name" column="c_name"/>
-
- <association property="teacher" column="teacher_id" javaType="Teacher">
- <id property="id" column="t_id"/>
- <result property="name" column="t_name"/>
- </association>
- </resultMap>
- <select id="getClassInfo2" parameterType="int" resultMap="ClassResultMap2" >
- select * from class where c_id = #{id}
- </select>
-
-
- <resultMap type="Classes" id="ClassResultMap2">
- <id property="id" column="c_id"/>
- <result property="name" column="c_name"/>
- <association property="teacher" column="teacher_id"
- javaType="Teacher" select="getTeacher">
- </association>
- </resultMap>
-
- <select id="getTeacher" parameterType="int" resultType="Teacher">
- select t_id id,t_name name from teacher where t_id=#{id}
- </select>
-
-
相关阅读:
IntelliJ IDEA设置代码括号对齐方式
cygwin完全安装步骤方法(过程图解)
IntelliJ IDEA(2017)安装和破解
ANDROID学习之路
最新Android系统版本与API等级对应关系表
Matlab 2016b 正式版下载
山东省高等学校教师资格考试题库(附答案)
Java中List集合去除重复数据的方法
jquery判断选择元素是否存在
人民币金额转化汉字的java写法
-
原文地址:https://www.cnblogs.com/gtbky/p/8351291.html
Copyright © 2020-2023
润新知