Mybais 标签
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mybais 标签相关的知识,希望对你有一定的参考价值。
trim
prefix="SET"前缀设置为SET
suffixOverrides="," 去掉最后的,
suffix : 后缀设置
prefixOverrides :去掉前缀多余的
<update id="updateUser1" parameterType="user"> UPDATE `USER` <trim prefix="SET" suffixOverrides=","> <if test="name != null and name != ‘‘"> `NAME` = #{name}, </if> <if test="password != null and password != ‘‘"> `PASSWORD` = #{password}, </if> <if test="email != null and email != ‘‘"> `EMAIL` = #{email}, </if> </trim> WHERE `USER_ID` = #{id} </update>
<update id="updateUser2" parameterType="user"> UPDATE `USER` <trim prefix="SET" suffixOverrides="," suffix="WHERE `USER_ID` = #{id}"> <if test="name != null and name != ‘‘"> `NAME` = #{name}, </if> <if test="password != null and password != ‘‘"> `PASSWORD` = #{password}, </if> <if test="email != null and email != ‘‘"> `EMAIL` = #{email}, </if> </trim> </update>
set
默认去掉最后的,
<update id="updateUser" parameterType="user"> UPDATE `USER` <set> <if test="name != null and name != ‘‘"> `NAME` = #{name}, </if> <if test="password != null and password != ‘‘"> `PASSWORD` = #{password}, </if> <if test="email != null and email != ‘‘"> `EMAIL` = #{email}, </if> </set> WHERE `USER_ID` = #{id} </update>
where
如果name为null或者为‘‘<where>后面的内容将无效
如果name有值<where>标签将会自动加上where
<select id="selectByName" parameterType="string" resultType="user"> SELECT t_user.`USER_ID` id, t_user.`NAME` name, t_user.`PASSWORD` password, t_user.`EMAIL` email, t_user.`LOCKED` locked, t_user.`ENABLED` enabled, t_user.`EXPIRATION` expiration, t_user.`CREATEDATE` createDate FROM `USER` AS t_user <where> <if test="name != null and name != ‘‘"> t_user.`NAME` = #{name} </if> </where> </select>
以上是关于Mybais 标签的主要内容,如果未能解决你的问题,请参考以下文章