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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
<?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="com.example.excel_upload.dao.UserDao">
<resultMap type="com.example.excel_upload.entity.User" id="UserMap">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="username" column="username" jdbcType="VARCHAR"/>
<result property="password" column="password" jdbcType="VARCHAR"/>
<result property="nickname" column="nickname" jdbcType="VARCHAR"/>
<result property="phone" column="phone" jdbcType="VARCHAR"/>
<result property="email" column="email" jdbcType="VARCHAR"/>
</resultMap>
<!--查询单个-->
<select id="queryById" resultMap="UserMap">
select id,
username,
password,
nickname,
phone,
email
from user
where id = #{id}
</select>
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="UserMap">
select
id, username, password, nickname, phone, email
from user
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="username != null and username != ''">
and username = #{username}
</if>
<if test="password != null and password != ''">
and password = #{password}
</if>
<if test="nickname != null and nickname != ''">
and nickname = #{nickname}
</if>
<if test="phone != null and phone != ''">
and phone = #{phone}
</if>
<if test="email != null and email != ''">
and email = #{email}
</if>
</where>
limit #{pageable.offset}, #{pageable.pageSize}
</select>
<!--查询所有数据-->
<select id="queryAll" resultMap="UserMap">
select
id, username, password, nickname, phone, email
from user
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="username != null and username != ''">
and username = #{username}
</if>
<if test="password != null and password != ''">
and password = #{password}
</if>
<if test="nickname != null and nickname != ''">
and nickname = #{nickname}
</if>
<if test="phone != null and phone != ''">
and phone = #{phone}
</if>
<if test="email != null and email != ''">
and email = #{email}
</if>
</where>
</select>
<!--统计总行数-->
<select id="count" resultType="java.lang.Long">
select count(1)
from user
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="username != null and username != ''">
and username = #{username}
</if>
<if test="password != null and password != ''">
and password = #{password}
</if>
<if test="nickname != null and nickname != ''">
and nickname = #{nickname}
</if>
<if test="phone != null and phone != ''">
and phone = #{phone}
</if>
<if test="email != null and email != ''">
and email = #{email}
</if>
</where>
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into user(username, password, nickname, phone, email)
values (#{username}, #{password}, #{nickname}, #{phone}, #{email})
</insert>
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into user(username, password, nickname, phone, email)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.username}, #{entity.password}, #{entity.nickname}, #{entity.phone}, #{entity.email})
</foreach>
</insert>
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
insert into user(username, password, nickname, phone, email)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.username}, #{entity.password}, #{entity.nickname}, #{entity.phone}, #{entity.email})
</foreach>
on duplicate key update
username = values(username),
password = values(password),
nickname = values(nickname),
phone = values(phone),
email = values(email)
</insert>
<!--通过主键修改数据-->
<update id="update">
update user
<set>
<if test="username != null and username != ''">
username = #{username},
</if>
<if test="password != null and password != ''">
password = #{password},
</if>
<if test="nickname != null and nickname != ''">
nickname = #{nickname},
</if>
<if test="phone != null and phone != ''">
phone = #{phone},
</if>
<if test="email != null and email != ''">
email = #{email},
</if>
</set>
where id = #{id}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete
from user
where id = #{id}
</delete>
</mapper>
|