五分钟带你玩转mybatis(二)常用标签
【摘要】
1.<select>
2.<insert>
3.<update>
4.<delete>
5.<foreach>
<foreach collection="barcodeManageBo" item="object" separator="," o...
1.<select>
2.<insert>
3.<update>
4.<delete>
5.<foreach>
-
<foreach collection="barcodeManageBo" item="object" separator=","
-
open="(" close=")">
-
#{object.id}
-
</foreach>
open;以什么开始
close:以什么结束
separator:分隔符
collection:list名称
item:index名称
6.<sql>
-
<sql id="sqlvalues">
-
<if test="code!=null or code !=''">#{code},</if>
-
<if test="itemname !=null or itemname !=''">#{itemname},</if>
-
<if test="criteria !=null or criteria !=''">#{criteria},</if>
-
</sql>
7.<include>>
<include refid="sqlvalues"></include>
引用sql标签
8.<set>
-
<set>
-
<if test="typeName != null and typeName != ''">
-
typeName ={typeName},
-
</if>
-
<if test="sort != null and sort != ''">sort = #{sort},</if>
-
</set>
在set时候省略最后一个符号
9.trim标签
-
<trim suffix="" suffixOverrides=",">
-
<if test="code!=null"> code = #{code},</if>
-
<if test="itemname !=null"> itemname =#{itemname},</if>
-
<if test="criteria !=null "> criteria =#{criteria},</if>
-
</trim>
prefix:前缀覆盖并增加其内容
suffix:后缀覆盖并增加其内容
prefixOverrides:前缀判断的条件
suffixOverrides:后缀判断的条件
将,变成空格
10.<if>标签
11.<choose >
-
<choose>
-
<when test="title != null">
-
and title = #{title}
-
</when>
-
<when test="content != null">
-
and content = #{content}
-
</when>
-
<otherwise>
-
and owner = "owner1"
-
</otherwise>
-
</choose>
12.<resultMap>
-
<resultMap id="getStudentRM" type="EStudnet">
-
<id property="id" column="ID"/>
-
<result property="studentName" column="Name"/>
-
<result property="studentAge" column="Age"/>
-
</resultMap>
-
<select id="getStudent" resultMap="getStudentRM">
-
SELECT ID, Name, Age
-
FROM TStudent
-
</select>
其他sql小技巧
时间转为String
DATE_FORMAT(scanDate,'%Y-%m-%d %H:%i') as scanDate,
文章来源: baocl.blog.csdn.net,作者:小黄鸡1992,版权归原作者所有,如需转载,请联系作者。
原文链接:baocl.blog.csdn.net/article/details/83345691
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)