文章目录
1.结果集:
<resultMap id="BaseResultMap" type="xx.xxBasicPO" >
<result column="id" property="id" jdbcType="BIGINT" />
</resultMap>
2.代码块:
2.1. 代码块(可被引用)
<sql id="Base_Column_List" >
id
</sql>
2.2. 分支(if else)
<choose>
<when test='test1'>
分支1
</when>
<when test='test2'>
分支2
</when>
<otherwise>
其他情况
</otherwise>
</choose>
3.1 添加语句:
<insert id="MethodName" parameterType="xx.xx.POName">
INSERT INTO
t_name
(
id ,
is_delete,
create_user,
update_user
)
VALUES
(
#{id},
#{isDelete},
#{createUser},
#{updateUser}
)
</insert>
3.2. 添加语句(主键自增,并返回主键)
<insert id="MethodName" parameterType="xx.xx.POName" useGeneratedKeys="true"
keyProperty="id">
INSERT INTO
t_name
(
id ,
is_delete,
create_user,
update_user
)
VALUES
(
#{id},
#{isDelete},
#{createUser},
#{updateUser}
)
</insert>
4.逻辑删除语句:
<update id="MethodName" parameterType="java.util.List">
update t_name
set
is_delete = 1
WHERE id in
<foreach collection="list" item="id" open="(" separator="," close=")" >
#{id}
</foreach>
</update>
5.物理删除语句:
<delete id="MethodName" parameterType="java.util.List">
delete from t_name
WHERE id in
<foreach collection="list" item="id" open="(" separator="," close=")" >
#{id}
</foreach>
</delete >
6.修改语句:
<update id="MethodName" parameterType="xx.xx.POName">
UPDATE t_name
<trim prefix="SET" suffixOverrides=",">
<if test='isDelete != null and isDelete != ""'>
is_delete=#{isDelete},
</if>
<if test='createUser != null and createUser != ""'>
create_user=#{createUser},
</if>
<if test='updateUser != null and updateUser != ""'>
update_user=#{updateUser},
</if>
</trim>
WHERE id=#{id}
</update>
7.查询语句:
<select id = "MethodName" resultMap="IdOfResultMap">
sql..
</select >
8.动态查询:
select columnNm from tableNm
<trim prefix="where" prefixOverrides="and|or">
<if test='null != columnNm and ""!= columnNm and "1"==columnNm '>
and tableNm.columnNm= #{columnNm}
</if>
</trim>
9.List集合遍历
<update id="deleteDetail" parameterType="java.util.List">
update t_detail
set
is_delete = 1
WHERE id in
<foreach collection="list" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</update>
10.查询结果类型与xml属性映射关系
结果类型 | resultMap/resultType | 值 |
---|---|---|
Object | resultMap | 维护的Object 的resultMap结果集 |
List<Object> | resultMap | 维护的Object 的resultMap结果集 |
String | resultType | java.lang.String |
List<String> | resultType | java.lang.String |
被<![CDATA[]]>这个标记所包含的内容将表示为纯文本:
<![CDATA[ sql ]]>