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.

89 lines
3.8 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" />
<association property="role" column="role_id" select="org.example.mapper.RoleMapper.selectRoleById"></association>
</resultMap>
<sql id="selectUserVo">
select id, username, password, role_id, phone, createdate, remark from user
</sql>
<select id="selectUserList" parameterType="User" resultMap="UserResult">
<include refid="selectUserVo"/>
<where>
<if test="username != null and username != ''"> and username like concat('%',#{username},'%')</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>
</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>
</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>
</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>
</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>