-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjdao-dynamic.xml
100 lines (91 loc) · 2.96 KB
/
jdao-dynamic.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.github.donnie4w.jdao.action.Dynamic">
<!-- where if -->
<select id="demo1" resultType="io.github.donnie4w.jdao.dao.Hstest">
SELECT * FROM hstest
<where>
<if test="rowname!= 'hello'">
and rowname = #{rowname}
</if>
<if test="id >0">
AND id = #{id}
</if>
</where>
</select>
<!-- trim -->
<select id="demo2" resultType="io.github.donnie4w.jdao.dao.Hstest">
SELECT * FROM hstest
<trim prefix="WHERE" prefixOverrides="AND|OR">
<if test="rowname != null">
AND rowname = #{rowname}
</if>
<if test="id != null">
AND id = #{id}
</if>
</trim>
</select>
<!-- foreach -->
<select id="demo3" resultType="io.github.donnie4w.jdao.dao.Hstest">
SELECT * FROM hstest where 1=1 and id in
<foreach collection="list" item="id" index="index" separator="," open="(" close=")">
#{id}
</foreach>
</select>
<!-- foreach -->
<select id="demo4" resultType="io.github.donnie4w.jdao.dao.Hstest">
SELECT * FROM hstest where 1=1 and id in
<foreach collection="hstest" item="item" index="index" separator="," open="(" close=")">
<if test="item.id > 0">
#{item.id}
</if>
</foreach>
</select>
<!-- foreach -->
<select id="demo5" resultType="io.github.donnie4w.jdao.dao.Hstest">
SELECT * FROM hstest where 1=1 and id in
<foreach collection="list" item="item" index="index" separator="," open="(" close=")">
<!-- index>=2 && index <=5 特殊符号需转义 -->
<if test="index >= 2 && index <= 5">
#{item}
</if>
</foreach>
</select>
<!-- choose -->
<select id="demo6" resultType="io.github.donnie4w.jdao.dao.Hstest">
SELECT * FROM hstest where 1=1
<choose>
<when test="rowname != 'hello'">
and rowname = #{rowname}
</when>
<when test="id > 0">
AND id = #{id}
</when>
<otherwise>
AND id = 1
</otherwise>
</choose>
</select>
<!-- set -->
<update id="dome7">
UPDATE hstest1
<set>
<trim suffixOverrides=",">
<if test="rowname != null">
rowname = #{rowname},
</if>
<if test="value != null">
value = #{value},
</if>
<if test="goto != null">
goto = #{goto},
</if>
</trim>
</set>
<where>
id = #{id}
</where>
</update>
</mapper>