第九次作业

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仓库

相关推荐
Bruce Deeg1 小时前
springcloud-gateway 网关组件中文文档
spring boot·spring·spring cloud
javaer炒粉1 小时前
Es结合springboot(笔记回忆)
spring boot·笔记·elasticsearch
刘zy_95272 小时前
Spring的AOP概念详解
java·后端·spring
我焦虑的编程日记2 小时前
【Java EE】Spring IOC&DI
java·spring·java-ee
askah66443 小时前
mfc140.dll怎么安装?mfc140.dll丢失安装详细解决方法
windows·microsoft·dll修复·dll丢失
李博客3 小时前
spring boot 整合 sentinel
java·spring boot·sentinel
哗哗的世界3 小时前
技术派Spring事件监听机制及原理
spring boot·spring·事件监听
不说废话斯基5 小时前
maven项目、idea抽风问题解决
java·maven·intellij-idea
Bruce Deeg5 小时前
IT专业入门,高考假期预习指南
java·spring·eclipse·idea·高考
bcdaren6 小时前
《Windows API每日一练》7.4 状态报告上使用计时器
c语言·汇编·windows