7.还续Dao及MyBatis的映射配置-查看文章

7.还续Dao及MyBatis的映射配置

发表于:2017-06-24 10:11:36 分类:博客源码 阅读:833次

13.UserMapper

package top.ersredma.blog.dao;


import org.apache.ibatis.annotations.Param;
import top.ersredma.blog.bean.User;

import java.util.List;

public interface UserMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(User record);

    int insertSelective(User record);

    User selectByPrimaryKey(Integer id);

    User selectByEmail(String email);

    int updateByPrimaryKeySelective(User record);

    int updateByPrimaryKey(User record);

    User selectUserByEmailAndPassword(@Param("email") String email,@Param("password") String password);

    User selectByUrl(@Param("userurl") String userurl);

    List selectUsersByKey(String key);
}

14.UserMapper.xml

<?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="top.ersredma.blog.dao.UserMapper" >
  <resultMap id="BaseResultMap" type="top.ersredma.blog.bean.User" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="password" property="password" jdbcType="VARCHAR" />
    <result column="sex" property="sex" jdbcType="VARCHAR" />
    <result column="introduce" property="introduce" jdbcType="VARCHAR" />
    <result column="img" property="img" jdbcType="VARCHAR" />
    <result column="email" property="email" jdbcType="VARCHAR" />
    <result column="birthday" property="birthday" jdbcType="VARCHAR" />
    <result column="state" property="state" jdbcType="INTEGER" />
  </resultMap>
  <resultMap id="AResultMap" type="top.ersredma.blog.bean.User" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="password" property="password" jdbcType="VARCHAR" />
    <result column="sex" property="sex" jdbcType="VARCHAR" />
    <result column="introduce" property="introduce" jdbcType="VARCHAR" />
    <result column="img" property="img" jdbcType="VARCHAR" />
    <result column="email" property="email" jdbcType="VARCHAR" />
    <result column="birthday" property="birthday" jdbcType="VARCHAR" />
    <result column="state" property="state" jdbcType="INTEGER" />
    <collection property="blogRolls" ofType="top.ersredma.blog.bean.BlogRoll">
      <id column="b_id" property="id" jdbcType="INTEGER" />
      <result column="b_user_id" property="userId" jdbcType="INTEGER" />
      <result column="b_describe" property="describe" jdbcType="VARCHAR" />
      <result column="b_url" property="url" jdbcType="VARCHAR" />
    </collection>
  </resultMap>
  <resultMap id="BResultMap" type="top.ersredma.blog.bean.User" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="password" property="password" jdbcType="VARCHAR" />
    <result column="sex" property="sex" jdbcType="VARCHAR" />
    <result column="introduce" property="introduce" jdbcType="VARCHAR" />
    <result column="img" property="img" jdbcType="VARCHAR" />
    <result column="email" property="email" jdbcType="VARCHAR" />
    <result column="birthday" property="birthday" jdbcType="VARCHAR" />
    <result column="state" property="state" jdbcType="INTEGER" />
    <association property="blog" javaType="top.ersredma.blog.bean.Blog">
      <id column="bl_id" property="id"/>
      <result column="bl_url" property="url" jdbcType="VARCHAR" />
      <result column="bl_blogname" property="blogname" jdbcType="VARCHAR" />
      <result column="bl_blogintro" property="blogintro" jdbcType="VARCHAR" />
      <result column="bl_state" property="state" jdbcType="INTEGER" />
      <result column="bl_user_id" property="userId" jdbcType="INTEGER" />
      <result column="bl_pv" property="pv" jdbcType="INTEGER" />
    </association>
    <collection property="blogRolls" ofType="top.ersredma.blog.bean.BlogRoll">
      <id column="b_id" property="id" jdbcType="INTEGER" />
      <result column="b_user_id" property="userId" jdbcType="INTEGER" />
      <result column="b_describe" property="describe" jdbcType="VARCHAR" />
      <result column="b_url" property="url" jdbcType="VARCHAR" />
    </collection>
    <collection property="cates" ofType="top.ersredma.blog.bean.Category">
      <id column="c_id" property="id" jdbcType="INTEGER" />
      <result column="c_user_id" property="userId" jdbcType="INTEGER" />
      <result column="c_catname" property="catname" jdbcType="VARCHAR" />
    </collection>
  </resultMap>
  <sql id="Base_Column_List" >
    id, name, password, sex, introduce, img, email, birthday, state
  </sql>
  <select id="selectUsersByKey" resultMap="BResultMap" >
    select
    u.id, u.name, u.password, u.sex, u.introduce, u.img, u.email, u.birthday, u.state,
    bl.url bl_url,bl.user_id bl_user_id,bl.blogname bl_blogname
    from user u,blog bl
    WHERE u.id=bl.user_id AND (u.name like concat(concat('%', #{key,jdbcType=VARCHAR}),'%') or bl.url like concat(concat('%', #{key,jdbcType=VARCHAR}),'%'))
  </select>
  <select id="selectByPrimaryKey" resultMap="AResultMap" parameterType="java.lang.Integer" >
    select
    u.id, u.name, u.password, u.sex, u.introduce, u.img, u.email, u.birthday, u.state,
    b.id b_id, b.user_id b_user_id, b.describe b_describe, b.url b_url
    from user u,blogroll b
    WHERE u.id=b.user_id AND u.id = #{id,jdbcType=INTEGER}
  </select>
  <select id="selectByUrl" resultMap="BResultMap" parameterType="java.lang.String" >
    SELECT
    u.id, u.name, u.password, u.sex, u.introduce, u.img, u.email, u.birthday, u.state,
    b.id b_id, b.user_id b_user_id, b.describe b_describe, b.url b_url,
    bl.id bl_id,bl.url bl_url,bl.blogname bl_blogname,bl.blogintro bl_blogintro,bl.state bl_state,bl.user_id bl_user_id,bl.pv bl_pv,
    c.id c_id,c.catname c_catname,c.user_id c_user_id
    FROM USER u,blogroll b,blog bl,category c
    WHERE (u.id=b.user_id or b.user_id=0) AND u.id=bl.user_id AND (u.id=c.user_id or c.user_id=0) AND bl.url= #{userurl,jdbcType=VARCHAR} AND u.state=0 AND bl.state=0
  </select>
  <select id="selectByEmail" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select
    <include refid="Base_Column_List" />
    from user
    where email = #{email,jdbcType=VARCHAR}
  </select>
  <select id="selectUserByEmailAndPassword" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from user
    where email = #{email,jdbcType=VARCHAR} and password = #{password,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from user
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="top.ersredma.blog.bean.User" >
    insert into user (id, name, password, 
      sex, introduce, img, 
      email, birthday
      )
    values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, 
      #{sex,jdbcType=VARCHAR}, #{introduce,jdbcType=VARCHAR}, #{img,jdbcType=VARCHAR}, 
      #{email,jdbcType=VARCHAR}, #{birthday,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="top.ersredma.blog.bean.User" >
    insert into user
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="name != null" >
        name,
      </if>
      <if test="password != null" >
        password,
      </if>
      <if test="sex != null" >
        sex,
      </if>
      <if test="introduce != null" >
        introduce,
      </if>
      <if test="img != null" >
        img,
      </if>
      <if test="email != null" >
        email,
      </if>
      <if test="birthday != null" >
        birthday,
      </if>
      <if test="state != null" >
        state,
      </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="password != null" >
        #{password,jdbcType=VARCHAR},
      </if>
      <if test="sex != null" >
        #{sex,jdbcType=VARCHAR},
      </if>
      <if test="introduce != null" >
        #{introduce,jdbcType=VARCHAR},
      </if>
      <if test="img != null" >
        #{img,jdbcType=VARCHAR},
      </if>
      <if test="email != null" >
        #{email,jdbcType=VARCHAR},
      </if>
      <if test="birthday != null" >
        #{birthday,jdbcType=VARCHAR},
      </if>
      <if test="state != null" >
        #{state,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="top.ersredma.blog.bean.User" >
    update user
    <set >
      <if test="name != null" >
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="password != null" >
        password = #{password,jdbcType=VARCHAR},
      </if>
      <if test="sex != null" >
        sex = #{sex,jdbcType=VARCHAR},
      </if>
      <if test="introduce != null" >
        introduce = #{introduce,jdbcType=VARCHAR},
      </if>
      <if test="img != null" >
        img = #{img,jdbcType=VARCHAR},
      </if>
      <if test="email != null" >
        email = #{email,jdbcType=VARCHAR},
      </if>
      <if test="birthday != null" >
        birthday = #{birthday,jdbcType=VARCHAR},
      </if>
      <if test="state != null" >
        state = #{state,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="top.ersredma.blog.bean.User" >
    update user
    set name = #{name,jdbcType=VARCHAR},
      password = #{password,jdbcType=VARCHAR},
      sex = #{sex,jdbcType=VARCHAR},
      introduce = #{introduce,jdbcType=VARCHAR},
      img = #{img,jdbcType=VARCHAR},
      email = #{email,jdbcType=VARCHAR},
      birthday = #{birthday,jdbcType=VARCHAR},
      state = #{state,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>


关键词:blog源码,dao


验证码:

  1. author
    包惜弱(伪装者) 2017-06-30 11:25:30
    码码在线观光团'