mybatis的标签

版权声明:欢迎转载,请附上转载地址 https://blog.csdn.net/qq_20143059/article/details/83345691

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,

猜你喜欢

转载自blog.csdn.net/qq_20143059/article/details/83345691
今日推荐