码迷,mamicode.com
首页 > 其他好文 > 详细

Mybais 标签

时间:2017-08-05 06:42:17      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:update   display   alt   one   enable   efi   result   sed   后缀   

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>
View Code
<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>
View Code

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 标签

标签:update   display   alt   one   enable   efi   result   sed   后缀   

原文地址:http://www.cnblogs.com/cainiaoYY/p/7288424.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!