首页 > 其他 > 详细

mybatis基础学习

时间:2019-10-06 18:09:10      阅读:59      评论:0      收藏:0      [点我收藏+]

1、

 

2、动态sql

2.1、if 标签 :

2.11、动态拼接sql语句;

<if test="name != null and !&quot;&quot;.equals(name.trim())">
and s.name like CONCAT(‘%‘,#{name},‘%‘)
</if>
<if test="courseId != null">
and s.course_id = #{courseId}
</if>

 

2.2、where 标签:

2.21、当if标签条件都不满足时,去除掉where关键字;

2.22、当多个if标签满足时,去除掉第一个多余的 and 关键字;

 

2.3、sql 标签:

2.31、定义查询的字段常量;

<sql id="constant">id,name</sql>

<select id="query" >
select <include refid="constant" /> from student
</select>

2.4、set 标签:
2.41、类似于 where 标签,用于update

2.5、trim 标签:
2.51、灵活前后添加去除字段标签;

2.6、choose 标签:

2.7、collection 标签:
2.71、主表关联子表;

2.8、association 标签:
2.81、子表关联主表;











mybatis基础学习

原文:https://www.cnblogs.com/aibaiyang/p/11627630.html

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