<?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.lxq.model.dao.UserDAO">

    <select id="getAllUser" resultType="com.lxq.model.object.User">
        select * from user
        <where>
            <if test="userId !=null">
                and userId = #{userId}
            </if>
            <if test="userAccount !=null">
                and userAccount like CONCAT('%', #{userAccount}, '%')
            </if>
            <if test="userName !=null">
                and userName like CONCAT('%', #{userName}, '%')
            </if>
            <if test="userPw !=null">
                and userPw = #{userPw}
            </if>
            <if test="userLv !=null">
                and userLv = #{userLv}
            </if>
            <if test="userSex !=null">
                and userSex = #{userSex}
            </if>
            <if test="userIphone !=null">
                and userIphone like CONCAT('%', #{userIphone}, '%')
            </if>

        </where>

    </select>
    <select id="getUser" resultType="com.lxq.model.object.User">
        select * from user
        <where>
            <if test="userId !=null">
                and userId = #{userId}
            </if>
            <if test="userAccount !=null">
                and userAccount = #{userAccount}
            </if>
            <if test="userName !=null">
                and userName like CONCAT('%', #{userName}, '%')
            </if>
            <if test="userPw !=null">
                and userPw = #{userPw}
            </if>
            <if test="userLv !=null">
                and userLv = #{userLv}
            </if>
            <if test="userSex !=null">
                and userSex = #{userSex}
            </if>
            <if test="userIphone !=null">
                and userIphone like CONCAT('%', #{userIphone}, '%')
            </if>

        </where>
    </select>

    <select id="getUserByAccount" resultType="com.lxq.model.object.User">
        select * from user where userAccount = #{userAccount}
    </select>

    <insert id="addUser"  parameterType="com.lxq.model.object.User">
        insert into user(userAccount,userName,userPw,userLv,userSex,userIphone)
        values(#{userAccount},#{userName},#{userPw},#{userLv},#{userSex},#{userIphone})
    </insert>

    <delete id="delUser" parameterType="com.lxq.model.object.User">
        delete from user
        where userAccount = #{userAccount}
    </delete>

    <update id="updateUser"  parameterType="com.lxq.model.object.User">
        update user
        <set>
            <if test="userName !=null">
                userName = #{userName},
            </if>
            <if test="userPw !=null">
                userPw = #{userPw},
            </if>
            <if test="userLv !=null">
                 userLv = #{userLv},
            </if>
            <if test="userSex !=null">
                 userSex = #{userSex},
            </if>
            <if test="userIphone !=null">
                userIphone = #{userIphone},
            </if>
        </set>
        where userId = #{userId}
    </update>


</mapper>