博客系统mapper.xml的分析(1)

AdminUserMapper.xml

管理员用户映射器

  • AdminUser login(@Param("userName") String userName, @Param("password") String password);
<!--登录验证-->
  <select id="login" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from tb_admin_user
    where login_user_name = #{userName,jdbcType=VARCHAR} AND login_password=#{password,jdbcType=VARCHAR} AND locked = 0
  </select>
  • AdminUser selectByPrimaryKey(Integer adminUserId);
<!--按照主键id查-->
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from tb_admin_user
    where admin_user_id = #{adminUserId,jdbcType=INTEGER}
  </select>
  • int insert(AdminUser record);
<!-- 插入数据,注册账户使用 放入的是一个AdminUser对象  -->
  <insert id="insert" parameterType="com.site.blog.my.core.entity.AdminUser">
    insert into tb_admin_user (admin_user_id, login_user_name, login_password, 
      nick_name, locked)
    values (#{adminUserId,jdbcType=INTEGER}, #{loginUserName,jdbcType=VARCHAR}, #{loginPassword,jdbcType=VARCHAR}, 
      #{nickName,jdbcType=VARCHAR}, #{locked,jdbcType=TINYINT})
  </insert>
  • int insertSelective(AdminUser record);
<!-- 插入数据,注册账户使用 放入的是一个AdminUser对象 (没有看懂这里可以用来做什么) -->
  <insert id="insertSelective" parameterType="com.site.blog.my.core.entity.AdminUser">
    insert into tb_admin_user
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="adminUserId != null">
        admin_user_id,
      </if>
      <if test="loginUserName != null">
        login_user_name,
      </if>
      <if test="loginPassword != null">
        login_password,
      </if>
      <if test="nickName != null">
        nick_name,
      </if>
      <if test="locked != null">
        locked,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="adminUserId != null">
        #{adminUserId,jdbcType=INTEGER},
      </if>
      <if test="loginUserName != null">
        #{loginUserName,jdbcType=VARCHAR},
      </if>
      <if test="loginPassword != null">
        #{loginPassword,jdbcType=VARCHAR},
      </if>
      <if test="nickName != null">
        #{nickName,jdbcType=VARCHAR},
      </if>
      <if test="locked != null">
        #{locked,jdbcType=TINYINT},
      </if>
    </trim>
  </insert>
  • int updateByPrimaryKeySelective(AdminUser record);
<!--  根据用户id来选择性更新数据 -->
  <update id="updateByPrimaryKeySelective" parameterType="com.site.blog.my.core.entity.AdminUser">
    update tb_admin_user
    <set>
      <if test="loginUserName != null">
        login_user_name = #{loginUserName,jdbcType=VARCHAR},
      </if>
      <if test="loginPassword != null">
        login_password = #{loginPassword,jdbcType=VARCHAR},
      </if>
      <if test="nickName != null">
        nick_name = #{nickName,jdbcType=VARCHAR},
      </if>
      <if test="locked != null">
        locked = #{locked,jdbcType=TINYINT},
      </if>
    </set>
    where admin_user_id = #{adminUserId,jdbcType=INTEGER}
  </update>
  • int updateByPrimaryKey(AdminUser record);
<!--  根据用户id来更新数据-->
  <update id="updateByPrimaryKey" parameterType="com.site.blog.my.core.entity.AdminUser">
    update tb_admin_user
    set login_user_name = #{loginUserName,jdbcType=VARCHAR},
      login_password = #{loginPassword,jdbcType=VARCHAR},
      nick_name = #{nickName,jdbcType=VARCHAR},
      locked = #{locked,jdbcType=TINYINT}
    where admin_user_id = #{adminUserId,jdbcType=INTEGER}
  </update>
  • 管理员用户类
public class AdminUser {
    private Integer adminUserId;    //管理员用户 ID

    private String loginUserName;   //登录用户名

    private String loginPassword;   //登录密码

    private String nickName;        //昵称

    private Byte locked;            //锁定情况

    public Integer getAdminUserId() {
        return adminUserId;
    }

    public void setAdminUserId(Integer adminUserId) {
        this.adminUserId = adminUserId;
    }

    public String getLoginUserName() {
        return loginUserName;
    }

    public void setLoginUserName(String loginUserName) {
        this.loginUserName = loginUserName == null ? null : loginUserName.trim();
    }

    public String getLoginPassword() {
        return loginPassword;
    }

    public void setLoginPassword(String loginPassword) {
        this.loginPassword = loginPassword == null ? null : loginPassword.trim();
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName == null ? null : nickName.trim();
    }

    public Byte getLocked() {
        return locked;
    }

    public void setLocked(Byte locked) {
        this.locked = locked;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", adminUserId=").append(adminUserId);
        sb.append(", loginUserName=").append(loginUserName);
        sb.append(", loginPassword=").append(loginPassword);
        sb.append(", nickName=").append(nickName);
        sb.append(", locked=").append(locked);
        sb.append("]");
        return sb.toString();
    }
}