0
点赞
收藏
分享

微信扫一扫

MyBatis入门介绍(三)

经过前面两个章节讲解,对mybatis应该有了大概了解,今天讲解下mapper文件的使用:
主要是select查询语句where条件的判断:
bigint类型的判空:

<if test="pkId != null">
and PK_ID = #{pkId}
</if>

varchar类型的判空:

<if test="listRemark != null and listRemark != ''">
and LIST_REMARK = #{listRemark}
</if>

datetime类型的判空:

<if test="createOper != null and createOper != ''">
and CREATE_OPER = #{createOper}
</if>

in语句的使用:

<if test="payWay != null and payWay != ''">
and PAY_WAY in ${payWay}
</if>

like语句的使用:

<if test="fromTradeName != null and fromTradeName != ''">
and FROM_TRADE_NAME like CONCAT('%', #{fromTradeName},'%')
</if>

CREATE_DATE时间间隔查询:

<if test="createDate != null">
<![CDATA[ and #{createDate} <= CREATE_DATE]]>
</if>
<if test="modifyDate != null">
<![CDATA[ and CREATE_DATE <= #{modifyDate}]]>
</if>

或者:

<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
AND date_format(u.create_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
AND date_format(u.create_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d')
</if>

批量删除:

<delete id="deleteUserByIds" parameterType="Long">
update sys_user set del_flag = '2' where user_id in
<foreach collection="array" item="userId" open="(" separator="," close=")">
#{userId}
</foreach>
</delete>

对应接口:

public int deleteUserByIds(Long[] userIds);


举报

相关推荐

Mybatis 入门介绍

Mybatis介绍

14MyBatis - MyBatis介绍

Mybatis入门

MyBatis入门

MyBatis(三)

0 条评论