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
| <!-- 多参数 -->
<select id="selectRoleByUserIdAndRoleEnabled" resultType="tk.mybatis.simple.model.SysRole">
select r.id,
r.role_name roleName,
r.enabled,
r.create_by createBy,
r.create_time createTime
from sys_user u inner join sys_user_role ur on u.id = ur.user_id
inner join sys_role r on ur.role_id = r.id
where u.id = #{userId} and r.enabled = #{enabled}
</select>
<!-- 参数为数组 xml中collection默认array-->
<select id="selectByIdList" resultType="tk.mybatis.simple.model.SysUser">
select id,
user_name userName,
user_password userPassword,
user_email userEmail,
user_info userInfo,
head_img headImg,
create_time createTime
from sys_user
where id in
<foreach collection="array" open="(" close=")" separator="," item="id" index="i">
#{id}
</foreach>
</select>
<!-- 参数为List xml中collection默认list -->
<insert id="insertList">
insert into sys_user (
user_name, user_password, user_email,
user_info, head_img, create_time
) values
<foreach collection="list" item="user" separator=",">
(
#{user.userName}, #{user.userPassword}, #{user.userEmail},
#{user.userInfo}, #{user.headImg, jdbcType=BLOB},
#{user.createTime, jdbcType=TIMESTAMP}
)
</foreach>
</insert>
<!--参数为Map xml中collection默认_parameter -->
<update id="updateByMap">
update sys_user
set
<foreach collection="_parameter" index="key" item="val" separator="," >
${key} = #{val}
</foreach>
where id = #{id}
</update>
<!--参数为多个数组 xml中collection=Param注解对应的名字-->
<select id="selectByIdOrUserNameList" resultType="tk.mybatis.simple.model.SysUser">
select id,
user_name userName,
user_password userPassword,
user_email userEmail,
user_info userInfo,
head_img headImg,
create_time createTime
from sys_user
where id in
<foreach collection="idArray" open="(" close=")" separator="," item="id" index="i">
#{id}
</foreach>
and user_name in
<foreach collection="nameArray" open="(" close=")" separator="," item="name" index="i">
#{name}
</foreach>
</select>
|