第九次作业

BookInfoMapper.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="com.rabbiter.bms.mapper.BookInfoMapper">
  <resultMap id="BaseResultMap" type="com.rabbiter.bms.model.BookInfo">
    <id column="bookId" jdbcType="INTEGER" property="bookid" />
    <result column="bookName" jdbcType="VARCHAR" property="bookname" />
    <result column="bookAuthor" jdbcType="VARCHAR" property="bookauthor" />
    <result column="bookPrice" jdbcType="DECIMAL" property="bookprice" />
    <result column="bookTypeId" jdbcType="INTEGER" property="booktypeid" />
    <result column="bookTypeName" jdbcType="INTEGER" property="booktypename" />
    <result column="bookDesc" jdbcType="VARCHAR" property="bookdesc" />
    <result column="isBorrowed" jdbcType="TINYINT" property="isborrowed" />
    <result column="bookImg" jdbcType="TINYINT" property="bookimg" />
  </resultMap>
  <sql id="Base_Column_List">
    bookId, bookName, bookAuthor, bookPrice, bookTypeId, bookDesc, isBorrowed, bookImg
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from book_info
    where bookId = #{bookid,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from book_info
    where bookId = #{bookid,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.rabbiter.bms.model.BookInfo">
    insert into book_info (bookId, bookName, bookAuthor, 
      bookPrice, bookTypeId, bookDesc, 
      isBorrowed, bookImg)
    values (#{bookid,jdbcType=INTEGER}, #{bookname,jdbcType=VARCHAR}, #{bookauthor,jdbcType=VARCHAR}, 
      #{bookprice,jdbcType=DECIMAL}, #{booktypeid,jdbcType=INTEGER}, #{bookdesc,jdbcType=VARCHAR}, 
      #{isborrowed,jdbcType=TINYINT}, #{bookimg,jdbcType=TINYINT})
  </insert>
  <insert id="insertSelective" parameterType="com.rabbiter.bms.model.BookInfo">
    insert into book_info
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="bookid != null">
        bookId,
      </if>
      <if test="bookname != null">
        bookName,
      </if>
      <if test="bookauthor != null">
        bookAuthor,
      </if>
      <if test="bookprice != null">
        bookPrice,
      </if>
      <if test="booktypeid != null">
        bookTypeId,
      </if>
      <if test="bookdesc != null">
        bookDesc,
      </if>
      <if test="isborrowed != null">
        isBorrowed,
      </if>
      <if test="bookimg != null">
        bookImg,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="bookid != null">
        #{bookid,jdbcType=INTEGER},
      </if>
      <if test="bookname != null">
        #{bookname,jdbcType=VARCHAR},
      </if>
      <if test="bookauthor != null">
        #{bookauthor,jdbcType=VARCHAR},
      </if>
      <if test="bookprice != null">
        #{bookprice,jdbcType=DECIMAL},
      </if>
      <if test="booktypeid != null">
        #{booktypeid,jdbcType=INTEGER},
      </if>
      <if test="bookdesc != null">
        #{bookdesc,jdbcType=VARCHAR},
      </if>
      <if test="isborrowed != null">
        #{isborrowed,jdbcType=TINYINT},
      </if>
      <if test="bookimg != null">
        #{bookimg,jdbcType=TINYINT},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.rabbiter.bms.model.BookInfo">
    update book_info
    <set>
      <if test="bookname != null">
        bookName = #{bookname,jdbcType=VARCHAR},
      </if>
      <if test="bookauthor != null">
        bookAuthor = #{bookauthor,jdbcType=VARCHAR},
      </if>
      <if test="bookprice != null">
        bookPrice = #{bookprice,jdbcType=DECIMAL},
      </if>
      <if test="booktypeid != null">
        bookTypeId = #{booktypeid,jdbcType=INTEGER},
      </if>
      <if test="bookdesc != null">
        bookDesc = #{bookdesc,jdbcType=VARCHAR},
      </if>
      <if test="isborrowed != null">
        isBorrowed = #{isborrowed,jdbcType=TINYINT},
      </if>
      <if test="bookimg != null">
        bookImg = #{bookimg,jdbcType=TINYINT},
      </if>
    </set>
    where bookId = #{bookid,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.rabbiter.bms.model.BookInfo">
    update book_info
    set bookName = #{bookname,jdbcType=VARCHAR},
      bookAuthor = #{bookauthor,jdbcType=VARCHAR},
      bookPrice = #{bookprice,jdbcType=DECIMAL},
      bookTypeId = #{booktypeid,jdbcType=INTEGER},
      bookDesc = #{bookdesc,jdbcType=VARCHAR},
      isBorrowed = #{isborrowed,jdbcType=TINYINT},
      bookImg = #{bookimg,jdbcType=TINYINT}
    where bookId = #{bookid,jdbcType=INTEGER}
  </update>
  <select id="selectAllByLimit" resultMap="BaseResultMap">
    select bookId, bookName, bookAuthor,bookPrice, bookTypeId, bookDesc,isBorrowed, bookImg,
           (select bookTypeName from book_type where book_type.bookTypeId = book_info.bookTypeId) as bookTypeName
    from book_info
    limit #{begin}, #{size}
  </select>
  <select id="selectCount" resultType="int">
    select count(*) from book_info
  </select>
  <select id="selectCountBySearch" resultType="int">
    select count(*) from book_info
    <where>
      <if test="bookname != null and bookname != '' ">
        and bookName like concat('%',#{bookname},'%')
      </if>
      <if test="bookauthor != null and bookauthor != '' ">
        and bookAuthor like concat('%',#{bookauthor},'%')
      </if>
      <if test="booktypeid != null and booktypeid != '' ">
        and bookTypeId = #{booktypeid}
      </if>
    </where>
  </select>
  <select id="selectBySearch" resultMap="BaseResultMap">
    select bookId, bookName, bookAuthor,bookPrice, bookTypeId, bookDesc,isBorrowed, bookImg,
           (select bookTypeName from book_type where book_type.bookTypeId = book_info.bookTypeId) as bookTypeName
    from book_info
    <where>
      <if test="bookname != null and bookname != '' ">
        and bookName like concat('%',#{bookname},'%')
      </if>
      <if test="bookauthor != null and bookauthor != '' ">
        and bookAuthor like concat('%',#{bookauthor},'%')
      </if>
      <if test="booktypeid != null and booktypeid != '' ">
        and bookTypeId = #{booktypeid}
      </if>
    </where>
    limit #{begin}, #{size}
  </select>
  <select id="selectAll" resultMap="BaseResultMap">
    select bookId, bookName, bookAuthor,bookPrice, bookTypeId, bookDesc,isBorrowed, bookImg,
           (select bookTypeName from book_type where book_type.bookTypeId = book_info.bookTypeId) as bookTypeName
    from book_info
  </select>
  <select id="selectCountByType" resultType="int">
    select count(*) from book_info
    <where>
      <if test="booktypeid != null and booktypeid != '' ">
        and bookTypeId = #{booktypeid}
      </if>
    </where>
  </select>
  <select id="selectByType" resultMap="BaseResultMap">
    select bookId, bookName, bookAuthor,bookPrice, bookTypeId, bookDesc,isBorrowed, bookImg,
    (select bookTypeName from book_type where book_type.bookTypeId = book_info.bookTypeId) as bookTypeName
    from book_info
    <where>
      <if test="booktypeid != null and booktypeid != '' ">
        and bookTypeId = #{booktypeid}
      </if>
    </where>
    limit #{begin}, #{size}
  </select>
</mapper>

BookTypeMapper.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="com.rabbiter.bms.mapper.BookTypeMapper">
  <resultMap id="BaseResultMap" type="com.rabbiter.bms.model.BookType">
    <id column="bookTypeId" jdbcType="INTEGER" property="booktypeid" />
    <result column="bookTypeName" jdbcType="VARCHAR" property="booktypename" />
    <result column="bookTypeDesc" jdbcType="VARCHAR" property="booktypedesc" />
  </resultMap>
  <sql id="Base_Column_List">
    bookTypeId, bookTypeName, bookTypeDesc
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from book_type
    where bookTypeId = #{booktypeid,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from book_type
    where bookTypeId = #{booktypeid,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.rabbiter.bms.model.BookType">
    insert into book_type (bookTypeId, bookTypeName, bookTypeDesc
      )
    values (#{booktypeid,jdbcType=INTEGER}, #{booktypename,jdbcType=VARCHAR}, #{booktypedesc,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.rabbiter.bms.model.BookType">
    insert into book_type
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="booktypeid != null">
        bookTypeId,
      </if>
      <if test="booktypename != null">
        bookTypeName,
      </if>
      <if test="booktypedesc != null">
        bookTypeDesc,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="booktypeid != null">
        #{booktypeid,jdbcType=INTEGER},
      </if>
      <if test="booktypename != null">
        #{booktypename,jdbcType=VARCHAR},
      </if>
      <if test="booktypedesc != null">
        #{booktypedesc,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.rabbiter.bms.model.BookType">
    update book_type
    <set>
      <if test="booktypename != null">
        bookTypeName = #{booktypename,jdbcType=VARCHAR},
      </if>
      <if test="booktypedesc != null">
        bookTypeDesc = #{booktypedesc,jdbcType=VARCHAR},
      </if>
    </set>
    where bookTypeId = #{booktypeid,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.rabbiter.bms.model.BookType">
    update book_type
    set bookTypeName = #{booktypename,jdbcType=VARCHAR},
      bookTypeDesc = #{booktypedesc,jdbcType=VARCHAR}
    where bookTypeId = #{booktypeid,jdbcType=INTEGER}
  </update>
  <select id="selectAllByLimit" resultMap="BaseResultMap">
    select <include refid="Base_Column_List" />
    from book_type
    limit #{begin}, #{size}
  </select>
  <select id="selectCount" resultType="int">
    select count(*) from book_type
  </select>
  <select id="selectAll" resultMap="BaseResultMap">
    select <include refid="Base_Column_List" />
    from book_type
  </select>
  <select id="selectCountBySearch" resultType="int">
    select count(*) from book_type
    <where>
      <if test="booktypename != null and booktypename != '' ">
        and bookTypeName like concat('%',#{booktypename},'%')
      </if>
    </where>
  </select>
  <select id="selectBySearch" resultMap="BaseResultMap">
    select bookTypeId, bookTypeName, bookTypeDesc
    from book_type
    <where>
      <if test="booktypename != null and booktypename != '' ">
        and bookTypeName like concat('%',#{booktypename},'%')
      </if>
    </where>
    limit #{begin}, #{size}
  </select>
</mapper>

BorrowMapper.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="com.rabbiter.bms.mapper.BorrowMapper">
  <resultMap id="BaseResultMap" type="com.rabbiter.bms.model.Borrow">
    <id column="borrowId" jdbcType="INTEGER" property="borrowid" />
    <result column="userId" jdbcType="INTEGER" property="userid" />
    <result column="userName" jdbcType="INTEGER" property="username" />
    <result column="bookId" jdbcType="INTEGER" property="bookid" />
    <result column="bookName" jdbcType="INTEGER" property="bookname" />
    <result column="borrowTime" jdbcType="TIMESTAMP" property="borrowtime" />
    <result column="returnTime" jdbcType="TIMESTAMP" property="returntime" />
  </resultMap>
  <sql id="Base_Column_List">
    borrowId, userId, bookId, borrowTime, returnTime
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from borrow
    where borrowId = #{borrowid,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from borrow
    where borrowId = #{borrowid,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.rabbiter.bms.model.Borrow">
    insert into borrow (borrowId, userId, bookId, 
      borrowTime, returnTime)
    values (#{borrowid,jdbcType=INTEGER}, #{userid,jdbcType=INTEGER}, #{bookid,jdbcType=INTEGER}, 
      #{borrowtime,jdbcType=TIMESTAMP}, #{returntime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.rabbiter.bms.model.Borrow">
    insert into borrow
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="borrowid != null">
        borrowId,
      </if>
      <if test="userid != null">
        userId,
      </if>
      <if test="bookid != null">
        bookId,
      </if>
      <if test="borrowtime != null">
        borrowTime,
      </if>
      <if test="returntime != null">
        returnTime,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="borrowid != null">
        #{borrowid,jdbcType=INTEGER},
      </if>
      <if test="userid != null">
        #{userid,jdbcType=INTEGER},
      </if>
      <if test="bookid != null">
        #{bookid,jdbcType=INTEGER},
      </if>
      <if test="borrowtime != null">
        #{borrowtime,jdbcType=TIMESTAMP},
      </if>
      <if test="returntime != null">
        #{returntime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.rabbiter.bms.model.Borrow">
    update borrow
    <set>
      <if test="userid != null">
        userId = #{userid,jdbcType=INTEGER},
      </if>
      <if test="bookid != null">
        bookId = #{bookid,jdbcType=INTEGER},
      </if>
      <if test="borrowtime != null">
        borrowTime = #{borrowtime,jdbcType=TIMESTAMP},
      </if>
      <if test="returntime != null">
        returnTime = #{returntime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where borrowId = #{borrowid,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.rabbiter.bms.model.Borrow">
    update borrow
    set userId = #{userid,jdbcType=INTEGER},
      bookId = #{bookid,jdbcType=INTEGER},
      borrowTime = #{borrowtime,jdbcType=TIMESTAMP},
      returnTime = #{returntime,jdbcType=TIMESTAMP}
    where borrowId = #{borrowid,jdbcType=INTEGER}
  </update>
  <select id="selectAllByLimit" resultMap="BaseResultMap">
    select borrowId, userId, bookId, borrowTime, returnTime,
           (select userName from user where borrow.userId = user.userId) userName,
           (select bookName from book_info where borrow.bookId = book_info.bookId) bookName
    from borrow
    limit #{begin}, #{size}
  </select>
  <select id="selectCount" resultType="int">
    select count(*) from borrow
  </select>
  <select id="selectCountBySearch" resultType="int">
    select count(*)
    from borrow, user, book_info
    where borrow.userId = user.userId and borrow.bookId = book_info.bookId
    <if test="bookId != null and bookId != '' ">
      and borrow.bookId like concat('%',#{bookId},'%')
    </if>
    <if test="username != null and username != '' ">
      and userName like concat('%',#{username},'%')
    </if>
    <if test="bookname != null and bookname != '' ">
      and bookName like concat('%',#{bookname},'%')
    </if>
    <if test="userid != null and userid != '' ">
      and borrow.userId = #{userid}
    </if>
  </select>
  <select id="selectBySearch" resultMap="BaseResultMap">
    select borrowId, borrow.userId, borrow.bookId, borrowTime, returnTime, userName, bookName
    from borrow, user, book_info
    where borrow.userId = user.userId and borrow.bookId = book_info.bookId
    <if test="username != null and username != '' ">
      and userName like concat('%',#{username},'%')
    </if>
    <if test="bookname != null and bookname != '' ">
      and bookName like concat('%',#{bookname},'%')
    </if>
    <if test="userid != null and userid != '' ">
      and borrow.userId = #{userid}
    </if>
    limit #{begin}, #{size}
  </select>
  <select id="selectCountByReader" resultType="int">
    select count(*) from borrow
    where userId = #{userid}
  </select>
  <select id="selectAllByLimitByReader" resultMap="BaseResultMap">
    select borrowId, userId, bookId, borrowTime, returnTime,
           (select userName from user where borrow.userId = user.userId) userName,
           (select bookName from book_info where borrow.bookId = book_info.bookId) bookName
    from borrow
    where userId = #{userid}
    limit #{begin}, #{size}
  </select>
</mapper>

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="com.rabbiter.bms.mapper.UserMapper">
  <resultMap id="BaseResultMap" type="com.rabbiter.bms.model.User">
    <id column="userId" jdbcType="INTEGER" property="userid" />
    <result column="userName" jdbcType="VARCHAR" property="username" />
    <result column="userPassword" jdbcType="VARCHAR" property="userpassword" />
    <result column="isAdmin" jdbcType="TINYINT" property="isadmin" />
  </resultMap>
  <sql id="Base_Column_List">
    userId, userName, userPassword, isAdmin
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from user
    where userId = #{userid,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from user
    where userId = #{userid,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.rabbiter.bms.model.User">
    insert into user (userId, userName, userPassword, 
      isAdmin)
    values (#{userid,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{userpassword,jdbcType=VARCHAR}, 
      #{isadmin,jdbcType=TINYINT})
  </insert>
  <insert id="insertSelective" parameterType="com.rabbiter.bms.model.User">
    insert into user
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="userid != null">
        userId,
      </if>
      <if test="username != null">
        userName,
      </if>
      <if test="userpassword != null">
        userPassword,
      </if>
      <if test="isadmin != null">
        isAdmin,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="userid != null">
        #{userid,jdbcType=INTEGER},
      </if>
      <if test="username != null">
        #{username,jdbcType=VARCHAR},
      </if>
      <if test="userpassword != null">
        #{userpassword,jdbcType=VARCHAR},
      </if>
      <if test="isadmin != null">
        #{isadmin,jdbcType=TINYINT},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.rabbiter.bms.model.User">
    update user
    <set>
      <if test="username != null">
        userName = #{username,jdbcType=VARCHAR},
      </if>
      <if test="userpassword != null">
        userPassword = #{userpassword,jdbcType=VARCHAR},
      </if>
      <if test="isadmin != null">
        isAdmin = #{isadmin,jdbcType=TINYINT},
      </if>
    </set>
    where userId = #{userid,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.rabbiter.bms.model.User">
    update user
    set userName = #{username,jdbcType=VARCHAR},
      userPassword = #{userpassword,jdbcType=VARCHAR},
      isAdmin = #{isadmin,jdbcType=TINYINT}
    where userId = #{userid,jdbcType=INTEGER}
  </update>
  <select id="selectByUsernameAndPasswordAndIsAdmin" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from user
    where userName = #{username}
      and userPassword = #{password}
      and isAdmin = #{isAdmin}
    limit 1
  </select>
  <select id="selectByUsername" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from user
    where userName = #{username}
    limit 1
  </select>
  <select id="selectAllByLimit" resultMap="BaseResultMap">
    select <include refid="Base_Column_List" />
    from user
    limit #{begin}, #{size}
  </select>
  <select id="selectCount" resultType="int">
    select count(*) from user
  </select>
  <select id="selectAll" resultMap="BaseResultMap">
    select <include refid="Base_Column_List" />
    from user
  </select>
  <select id="selectCountBySearch" resultType="int">
    select count(*) from user
    <where>
      <if test="username != null and username != '' ">
        and userName like concat('%',#{username},'%')
      </if>
    </where>
  </select>
  <select id="selectBySearch" resultMap="BaseResultMap">
    select userId, userName, userPassword, isAdmin
    from user
    <where>
      <if test="username != null and username != '' ">
        and userName like concat('%',#{username},'%')
      </if>
    </where>
    limit #{begin}, #{size}
  </select>
</mapper>

创建Git仓库

相关推荐
hqxstudying21 分钟前
java依赖注入方法
java·spring·log4j·ioc·依赖
春生野草1 小时前
关于SpringMVC的整理
spring
Bug退退退1232 小时前
RabbitMQ 高级特性之重试机制
java·分布式·spring·rabbitmq
全栈凯哥2 小时前
02.SpringBoot常用Utils工具类详解
java·spring boot·后端
hello早上好3 小时前
CGLIB代理核心原理
java·spring
RainbowSea4 小时前
跨域问题(Allow CORS)解决(3 种方法)
java·spring boot·后端
RainbowSea4 小时前
问题 1:MyBatis-plus-3.5.9 的分页功能修复
java·spring boot·mybatis
sniper_fandc6 小时前
SpringBoot系列—入门
java·spring boot·后端
代码的余温7 小时前
Maven引入第三方JAR包实战指南
java·maven·jar
先睡9 小时前
Redis的缓存击穿和缓存雪崩
redis·spring·缓存