ProjectsMapper.xml
2.81 KB
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
<?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.project.demo.mapper.ProjectsMapper">
<resultMap id="projectsMap" type="com.project.demo.domain.Projects">
<result column="id" property="id" />
<result column="name" property="projectName" />
<result column="users_id" property="usersId" />
<result column="remark" property="remark" />
<result column="start_time" property="startTime" />
</resultMap>
<select id="search" resultMap="projectsMap" resultType="Map">
SELECT
*
FROM projects
where 1=1
<if test="params.projectsIds != null">
AND id in
<foreach collection="params.projectsIds" item="item" index="index"
open="(" separator="," close=")">
#{item}
</foreach>
</if>
ORDER BY id desc
</select>
<select id="findById" resultMap="projectsMap">
SELECT
*
FROM projects
where id = #{id}
</select>
<select id="findByUsersId" resultMap="projectsMap" resultType="Map">
SELECT
*
FROM projects
where users_id = #{usersId}
</select>
<update id="updateProjects" parameterType="com.project.demo.domain.Projects">
UPDATE projects
<set>
<if test="params.projectName != null">
name = #{params.projectName},
</if>
<if test="params.projectRemark != null">
remark = #{params.projectRemark},
</if>
</set>
WHERE
id = #{id}
</update>
<insert id="saveProjects" parameterType="com.project.demo.domain.Projects">
insert into projects
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="projectName != null">
name,
</if>
<if test="remark != null">
remark,
</if>
<if test="usersId != null">
users_id,
</if>
<if test="startTime != null">
start_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="projectName != null">
#{projectName},
</if>
<if test="remark != null">
#{remark},
</if>
<if test="usersId != null">
#{usersId},
</if>
<if test="startTime != null">
#{startTime},
</if>
</trim>
</insert>
<select id="findByStartTime" resultMap="projectsMap">
SELECT
*
FROM projects
where start_time = #{startTime}
</select>
</mapper>