<?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">
<!--suppress Annotator -->
<mapper namespace="test05.mapper.UserMapper">
    <select id="selectUser" resultType="test05.pojo.User">
        SELECT N_USER_ID AS id,
               VC_LOGIN_NAME AS name,
               VC_PASSWORD AS password
        FROM t_user
        WHERE
            #{user.id} IN (N_USER_ID, -1)
          AND VC_LOGIN_NAME LIKE CONCAT('%',#{user.name},'%')
          AND VC_PASSWORD LIKE CONCAT('%',#{user.password},'%')
        ORDER BY N_USER_ID DESC
        LIMIT #{offset},#{pageSize}
    </select>
    <insert id="insertUser" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO t_user
            (VC_LOGIN_NAME, VC_PASSWORD)
        VALUES
            (#{name}, #{password})
    </insert>
    <update id="updateUser">
        UPDATE t_user
        SET VC_PASSWORD=#{password},
            VC_LOGIN_NAME=#{name}
        WHERE N_USER_ID = #{id};
    </update>
    <delete id="deleteUser">
        DELETE
        FROM t_user
        WHERE N_USER_ID = #{id}
    </delete>
    <select id="selectUserByName" resultType="test05.pojo.User">
        SELECT N_USER_ID AS id,
               VC_LOGIN_NAME AS name,
               VC_PASSWORD AS password
        FROM t_user
        WHERE VC_LOGIN_NAME = #{username};
    </select>
</mapper>