Mybatis 标签

where 标签

用于处理select语句and等问题

1
2
3
4
5
6
7
8
<select id="version" parameterType="long" resultType="int">
SELECT column1, column2, columnN FROM table_name;
<where>
<if test="condition">
column1=#{value1}
</if>
</where>
</select>

set标签

用于处理update逗号,逗号等问题,与where类似

1
2
3
4
5
6
7
8
<update id="update" parameterType="UserAlias">
UPDATE table_name
<set>
<if test="condition">
column1 = #{value1}, column2 = #{value2}
</if>
</set>
</update>

##sql标签
sql标签与select等标签同级,相当于常量定义

1
2
3
4
5
<sql id="select_content">column1, column2, columnN</sql>
<select id="version" parameterType="long" resultType="int">
SELECT <include refid="select_content"></include> FROM table_name;
</select>

##trim标签
灵活的代替set或者where

1
2
<trim prefix="set" suffixOverrides=","></trim>
<trim prefix="where" prefixOverrides="and"></trim>

##choose标签
可以当做ifelse,也可以视为switch

1
2
3
4
5
6
<choose>
<when test=""></when>
<when test=""></when>
<when test=""></when>
<otherwise></otherwise>
</choose>

##collection与association标签
collection用来展示联合查询时子表内容的
association用来展示联合查询主表内容的

1
2
3
<collection property="javaBean的主表名" resultMap="Namespace.ResultMap的id"/>
<association property="javaBean的子表名" resultMap="Namespace.ResultMap的id></association>

##标签总结
all lable