首页 > 其他 > 详细

MyBatis的标签属性

时间:2019-11-12 19:40:27      阅读:106      评论:0      收藏:0      [点我收藏+]
<!--column不做限制,可以为任意表的字段,property必须type定义的pojo属性-->
<resultMap id="唯一的标识" type="映射的pojo对象">
<id column="表的主键字段,或者可以为查询语句中的别名字段" jdbcType="字段类型"
property="映射pojo对象的主键属性"/>
<result column="表的一个字段(可以为任意表的一个字段)" jdbcType="字段类型"
property="映射pojo对象的一个属性(须为type定义的pojo对象中的一个属性)"/>
<association property="pojo的一个对象属性" javaType="pojo关联的pojo对象">
<id column="关联pojo对象对应表的主键字段" javaType="字段类型"
property="关联pojo对象的主键属性"/>
<result column="任意表的字段" jdbcType="字段类型" property="关联pojo对象的属性"/>
</association>
<!--集合中的property须为oftype定义的pojo对象的属性-->
<!--<collection property="pojo的集合属性" ofType="集合中的pojo对象">
<id column="集合中pojo对象对应的表的主键字段" jdbcType="字段类型"
property="集合中pojo对象主键属性"/>
<result column="可以为任意表的一个字段" jdbcType="字段类型"
property="集合中的pojo对象的属性"/>
</collection>-->
<collection property="pojo的集合属性" ofType="集合中的pojo对象"
select="pojo对象的Dao层方法"
column="集合中pojo对象对应的表的字段">
</collection>
</resultMap>

例:
Dao层
List<Menu> findId(Integer roleId);
<!--根据用户ID查询关联的角色-->
<select id="findId" parameterType="int" resultMap="findUser">
SELECT m.* FROM t_menu m,t_role_menu rm WHERE m.id = rm.menu_id AND role_id = #{roleId} and level = 1
</select>
<resultMap id="findUser" type="com.itheima.pojo.Menu">
<!-- <id column="id" property="id"></id>
<result column="name" property="name"></result>
<result column="linkUrl" property="linkUrl"></result>
<result column="path" property="path"></result>
<result column="priority" property="priority"></result>
<result column="description" property="description"></result>
<result column="icon" property="icon"></result>-->
<collection property="children" ofType="com.itheima.pojo.Menu"
select="com.itheima.dao.MenuDao.getMenuByParentId"
column="id">
</collection>
</resultMap>

<select id="getMenuByParentId" parameterType="int" resultType="com.itheima.pojo.Menu">
SELECT * FROM `t_menu` t WHERE t.`level`=2 AND t.`parentMenuId`=#{id}
</select>

 

 

MyBatis的标签属性

原文:https://www.cnblogs.com/foshuo-cv/p/11843614.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!