UserMapper.xml 3.37 KB
<?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.monitor.mysql.mapper.UserMapper" >
  <resultMap id="BaseResultMap" type="com.model.User" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="pwd" property="pwd" jdbcType="VARCHAR" />
    <result column="level" property="level" jdbcType="INTEGER" />
    <result column="email" property="email" jdbcType="VARCHAR" />
    <result column="mobile" property="mobile" jdbcType="VARCHAR" />
    <result column="c_name" property="cname" jdbcType="VARCHAR" />
    <result column="role" property="role" jdbcType="VARCHAR" />
    <result column="modules" property="modules" jdbcType="VARCHAR" />
    <result column="module_groups" property="moduleGroups" jdbcType="VARCHAR" />

  </resultMap>

  <sql id="Base_Column_List" >
    id, name, pwd, level, email, mobile,c_name,role,modules,module_groups
  </sql>

  <select id="selectById" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select
    <include refid="Base_Column_List" />
    from user
    where id = #{id,jdbcType=INTEGER}
  </select>

  <select id="selectByName" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select
    <include refid="Base_Column_List" />
    from user
    where name = #{name,jdbcType=VARCHAR}
  </select>

  <select id="selectAll" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from user
  </select>

  <select id="selectUsers" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from user
    order by id desc
    limit #{startIndex},#{pageSize}
  </select>

  <select id="selectUsersByRole" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from user
    where role =  #{role}
  </select>

  <delete id="deleteById" parameterType="java.lang.Integer" >
    delete from user
    where id = #{id,jdbcType=INTEGER}
  </delete>

  <delete id="deleteByName" parameterType="java.lang.String" >
    delete from user
    where name = #{name,jdbcType=VARCHAR}
  </delete>

  <insert id="insert" parameterType="com.model.User" >
    insert into user
     (name,pwd,level,email,mobile,c_name,role,modules,module_groups, create_time, update_time)
    values
     (#{name,jdbcType=VARCHAR},#{pwd,jdbcType=VARCHAR},#{level,jdbcType=INTEGER},
     #{email,jdbcType=VARCHAR},#{mobile,jdbcType=VARCHAR},#{cname,jdbcType=VARCHAR},#{role,jdbcType=VARCHAR},
     #{modules,jdbcType=VARCHAR},#{moduleGroups,jdbcType=VARCHAR},
     now(),now())
  </insert>

  <update id="update" parameterType="com.model.User" >
    update user
    set level = #{level,jdbcType=INTEGER},
        email = #{email,jdbcType=VARCHAR},
        mobile = #{mobile,jdbcType=VARCHAR},
        role= #{role,jdbcType=VARCHAR},
        c_name= #{cname,jdbcType=VARCHAR},
        modules= #{modules,jdbcType=VARCHAR},
        module_groups= #{moduleGroups,jdbcType=VARCHAR},
        update_time = now()
    where id = #{id,jdbcType=INTEGER}
  </update>

  <update id="updatePwd" parameterType="com.model.User" >
    update user
    set pwd = #{pwd,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="selectCount" resultType="java.lang.Integer">
    select
    count(1)
    from user
  </select>
</mapper>