<?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.dao.UsersMapper">
    <resultMap id="BaseResultMap" type="com.entity.Users">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="uname" jdbcType="VARCHAR" property="uname"/>
        <result column="pwd" jdbcType="VARCHAR" property="pwd"/>
        <result column="img" jdbcType="VARCHAR" property="img"/>
        <result column="sex" jdbcType="VARCHAR" property="sex"/>
        <result column="address" jdbcType="VARCHAR" property="address"/>
        <result column="utype" jdbcType="VARCHAR" property="utype"/>
        <result column="tel" jdbcType="VARCHAR" property="tel"/>
        <result column="age" jdbcType="VARCHAR" property="age"/>
        <result column="email" jdbcType="VARCHAR" property="email"/>
        <result column="pubtime" jdbcType="VARCHAR" property="pubtime"/>
    </resultMap>
    <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.entity.Users">
        <result column="note" jdbcType="LONGVARCHAR" property="note"/>
    </resultMap>
    <sql id="Base_Column_List">
    id, `name`, uname, pwd, img, sex, address, utype, tel, age,  email,
    pubtime
  </sql>
    <sql id="Blob_Column_List">
    note
  </sql>
    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="ResultMapWithBLOBs">
        select
        <include refid="Base_Column_List"/>
        ,
        <include refid="Blob_Column_List"/>
        from users
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from users
    where id = #{id,jdbcType=INTEGER}
  </delete>
    <insert id="insert" parameterType="com.entity.Users">
    insert into users (id, `name`, uname,
      pwd, img, sex, address,
      utype, tel, age, email, pubtime,note)
    values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{uname,jdbcType=VARCHAR},
      #{pwd,jdbcType=VARCHAR}, #{img,jdbcType=VARCHAR}, #{sex,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR},
      #{utype,jdbcType=VARCHAR}, #{tel,jdbcType=VARCHAR}, #{age,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR},
       #{pubtime,jdbcType=VARCHAR}, #{note,jdbcType=LONGVARCHAR})
  </insert>
    <insert id="insertSelective" parameterType="com.entity.Users">
        insert into users
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="name != null">
                `name`,
            </if>
            <if test="uname != null">
                uname,
            </if>
            <if test="pwd != null">
                pwd,
            </if>
            <if test="img != null">
                img,
            </if>
            <if test="sex != null">
                sex,
            </if>
            <if test="address != null">
                address,
            </if>
            <if test="utype != null">
                utype,
            </if>
            <if test="tel != null">
                tel,
            </if>
            <if test="age != null">
                age,
            </if>
            <if test="email != null">
                email,
            </if>
            <if test="pubtime != null">
                pubtime,
            </if>
            <if test="note != null">
                note,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="name != null">
                #{name,jdbcType=VARCHAR},
            </if>
            <if test="uname != null">
                #{uname,jdbcType=VARCHAR},
            </if>
            <if test="pwd != null">
                #{pwd,jdbcType=VARCHAR},
            </if>
            <if test="img != null">
                #{img,jdbcType=VARCHAR},
            </if>
            <if test="sex != null">
                #{sex,jdbcType=VARCHAR},
            </if>
            <if test="address != null">
                #{address,jdbcType=VARCHAR},
            </if>
            <if test="utype != null">
                #{utype,jdbcType=VARCHAR},
            </if>
            <if test="tel != null">
                #{tel,jdbcType=VARCHAR},
            </if>
            <if test="age != null">
                #{age,jdbcType=VARCHAR},
            </if>
            <if test="email != null">
                #{email,jdbcType=VARCHAR},
            </if>
            <if test="pubtime != null">
                #{pubtime,jdbcType=VARCHAR},
            </if>
            <if test="note != null">
                #{note,jdbcType=LONGVARCHAR},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.entity.Users">
        update users
        <set>
            <if test="name != null">
                `name` = #{name,jdbcType=VARCHAR},
            </if>
            <if test="uname != null">
                uname = #{uname,jdbcType=VARCHAR},
            </if>
            <if test="pwd != null">
                pwd = #{pwd,jdbcType=VARCHAR},
            </if>
            <if test="img != null">
                img = #{img,jdbcType=VARCHAR},
            </if>
            <if test="sex != null">
                sex = #{sex,jdbcType=VARCHAR},
            </if>
            <if test="address != null">
                address = #{address,jdbcType=VARCHAR},
            </if>
            <if test="utype != null">
                utype = #{utype,jdbcType=VARCHAR},
            </if>
            <if test="tel != null">
                tel = #{tel,jdbcType=VARCHAR},
            </if>
            <if test="age != null">
                age = #{age,jdbcType=VARCHAR},
            </if>
            <if test="email != null">
                email = #{email,jdbcType=VARCHAR},
            </if>
            <if test="pubtime != null">
                pubtime = #{pubtime,jdbcType=VARCHAR},
            </if>
            <if test="note != null">
                note = #{note,jdbcType=LONGVARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.entity.Users">
    update users
    set `name` = #{name,jdbcType=VARCHAR},
      uname = #{uname,jdbcType=VARCHAR},
      pwd = #{pwd,jdbcType=VARCHAR},
      img = #{img,jdbcType=VARCHAR},
      sex = #{sex,jdbcType=VARCHAR},
      address = #{address,jdbcType=VARCHAR},
      utype = #{utype,jdbcType=VARCHAR},
      tel = #{tel,jdbcType=VARCHAR},
      age = #{age,jdbcType=VARCHAR},
      email = #{email,jdbcType=VARCHAR},
      pubtime = #{pubtime,jdbcType=VARCHAR},
      note = #{note,jdbcType=LONGVARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
    <update id="updateByPrimaryKey" parameterType="com.entity.Users">
    update users
    set `name` = #{name,jdbcType=VARCHAR},
      uname = #{uname,jdbcType=VARCHAR},
      pwd = #{pwd,jdbcType=VARCHAR},
      img = #{img,jdbcType=VARCHAR},
      sex = #{sex,jdbcType=VARCHAR},
      address = #{address,jdbcType=VARCHAR},
      utype = #{utype,jdbcType=VARCHAR},
      tel = #{tel,jdbcType=VARCHAR},
      age = #{age,jdbcType=VARCHAR},
      email = #{email,jdbcType=VARCHAR},
      pubtime = #{pubtime,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>


    <select id="login" parameterType="java.util.Map" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from users
        where uname = #{uname,jdbcType=VARCHAR} and pwd=#{pwd,jdbcType=VARCHAR}
    </select>
    <select id="checkName" parameterType="java.util.Map" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from users
        where uname = #{uname,jdbcType=VARCHAR}
    </select>
    <select id="getCount" parameterType="java.util.Map" resultType="int">
        select count(*) from users where 1=1
        <if test="uname != null">
            and uname like concat('%',#{uname,jdbcType=VARCHAR},'%')
        </if>
        <if test="utype != null">
            and utype like concat('%',#{utype,jdbcType=VARCHAR},'%')
        </if>
        <if test="name != null">
            and name like concat('%',#{name,jdbcType=VARCHAR},'%')
        </if>
    </select>
    <select id="getAll" parameterType="java.util.Map" resultMap="BaseResultMap">
        select * from users where 1=1
        <if test="uname != null">
            and uname like concat('%',#{uname,jdbcType=VARCHAR},'%')
        </if>
        <if test="utype != null">
            and utype like concat('%',#{utype,jdbcType=VARCHAR},'%')
        </if>
        <if test="name != null">
            and name like concat('%',#{name,jdbcType=VARCHAR},'%')
        </if>
        order by id desc
    </select>
    <select id="getByPage" parameterType="java.util.Map" resultMap="BaseResultMap">
        select * from users where 1=1
        <if test="uname != null">
            and uname like concat('%',#{uname,jdbcType=VARCHAR},'%')
        </if>
        <if test="utype != null">
            and utype like concat('%',#{utype,jdbcType=VARCHAR},'%')
        </if>
        <if test="name != null">
            and name like concat('%',#{name,jdbcType=VARCHAR},'%')
        </if>
        order by id desc
        <if test="pageno!=null and pageSize!=null">
            limit #{pageno},#{pageSize}
        </if>
    </select>

</mapper>
