第九次作业

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

相关推荐
阿伟*rui1 小时前
配置管理,雪崩问题分析,sentinel的使用
java·spring boot·sentinel
paopaokaka_luck3 小时前
【360】基于springboot的志愿服务管理系统
java·spring boot·后端·spring·毕业设计
Yaml45 小时前
Spring Boot 与 Vue 共筑二手书籍交易卓越平台
java·spring boot·后端·mysql·spring·vue·二手书籍
小小小妮子~5 小时前
Spring Boot详解:从入门到精通
java·spring boot·后端
hong1616885 小时前
Spring Boot中实现多数据源连接和切换的方案
java·spring boot·后端
aloha_7896 小时前
从零记录搭建一个干净的mybatis环境
java·笔记·spring·spring cloud·maven·mybatis·springboot
hairenjing11236 小时前
使用 Mac 数据恢复从 iPhoto 图库中恢复照片
windows·stm32·嵌入式硬件·macos·word
程序媛小果7 小时前
基于java+SpringBoot+Vue的旅游管理系统设计与实现
java·vue.js·spring boot
九鼎科技-Leo8 小时前
了解 .NET 运行时与 .NET 框架:基础概念与相互关系
windows·c#·.net
wyh要好好学习8 小时前
SpringMVC快速上手
java·spring