You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
4.5 KiB

<?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="org.example.mapper.UserMapper">
<resultMap type="User" id="UserResult">
<result property="id" column="id" />
<result property="username" column="username" />
<result property="password" column="password" />
<result property="roleId" column="role_id" />
<result property="phone" column="phone" />
<result property="createdate" column="createdate" />
<result property="remark" column="remark" />
<result property="realName" column="real_name" />
<result property="age" column="age" />
<result property="sex" column="sex" />
</resultMap>
<sql id="selectUserVo">
select id, username, password, role_id, phone, createdate, remark, real_name, age, sex from user
</sql>
<select id="selectUserList" parameterType="User" resultMap="UserResult">
<include refid="selectUserVo"/>
<where>
<if test="username != null and username != ''"> and username = #{username}</if>
<if test="realName != null and realName != ''"> and real_name like concat('%',#{realName},'%')</if>
<if test="sex != null and sex != ''"> and sex = #{sex}</if>
<if test="password != null and password != ''"> and password = #{password}</if>
<if test="roleId != null "> and role_id = #{roleId}</if>
<if test="phone != null and phone != ''"> and phone like concat('%', #{phone}, '%')</if>
<if test="createdate != null "> and createdate = #{createdate}</if>
</where>
order by id desc
</select>
<select id="selectUserById" parameterType="Integer" resultMap="UserResult">
<include refid="selectUserVo"/>
where id = #{id}
order by createdate desc
</select>
<select id="selectUserByUsername" parameterType="String" resultMap="UserResult">
<include refid="selectUserVo"/>
where username = #{username}
</select>
<insert id="insertUser" parameterType="User" useGeneratedKeys="true" keyProperty="id">
insert into user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="username != null">username,</if>
<if test="password != null and password != ''">password,</if>
<if test="roleId != null">role_id,</if>
<if test="phone != null and phone != ''">phone,</if>
<if test="createdate != null">createdate,</if>
<if test="remark != null">remark,</if>
<if test="realName != null">real_name,</if>
<if test="sex != null">sex,</if>
<if test="age != null">age,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="username != null">#{username},</if>
<if test="password != null and password != ''">#{password},</if>
<if test="roleId != null">#{roleId},</if>
<if test="phone != null and phone != ''">#{phone},</if>
<if test="createdate != null">#{createdate},</if>
<if test="remark != null">#{remark},</if>
<if test="realName != null">#{realName},</if>
<if test="sex != null">#{sex},</if>
<if test="age != null">#{age},</if>
</trim>
</insert>
<update id="updateUser" parameterType="User">
update user
<trim prefix="SET" suffixOverrides=",">
<if test="username != null">username = #{username},</if>
<if test="password != null and password != ''">password = #{password},</if>
<if test="roleId != null">role_id = #{roleId},</if>
<if test="phone != null and phone != ''">phone = #{phone},</if>
<if test="createdate != null">createdate = #{createdate},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="realName != null">real_name = #{realName},</if>
<if test="sex != null">sex = #{sex},</if>
<if test="age != null">age = #{age},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteUserById" parameterType="Integer">
delete from user where id = #{id}
</delete>
<delete id="deleteUserByIds" parameterType="String">
delete from user where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>