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>
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 标签的主要内容,如果未能解决你的问题,请参考以下文章

MyBais入门

Mybais面试题

mybais学习————纯jdbc编程

如何通过代码设置片段标签?

Spring框架整合mybais框架-注入映射器實現

Android中切换标签片段之间的延迟