Skip to content

Commit

Permalink
Add book.xml and admin.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghuanhao committed Feb 13, 2019
1 parent 2023516 commit 9f7f969
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/resources/MyBatis/admin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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.library.dao.AdminDao">
<select id="getMatchCount" resultType="int" parameterType="com.library.bean.Admin">
select count(*) from admin
where admin_id = #{admin_id}
and password = #{password}
</select>
<update id="resetPassword" parameterType="com.library.bean.Admin">
update admin set password = #{password}
where admin_id = #{admin_id}
</update>
<select id="getPassword" resultType="String" parameterType="long">
select password from admin where admin_id = #{admin_id}
</select>
<select id="getUsername" resultType="String" parameterType="long">
select username from admin where admin_id = #{admin_id}
</select>
</mapper>
33 changes: 33 additions & 0 deletions src/main/resources/MyBatis/book.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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.library.dao.BookDao">
<insert id="addBook" parameterType="com.library.bean.Book">
insert into book_info values
(null, #{name}, #{author}, #{publish}, #{ISBN},
#{introduction}, #{language}, #{price}, #{pub_date},
#{class_id}, #{number})
</insert>
<update id="editBook" parameterType="com.library.bean.Book">
update book_info set name=#{name}, author=#{author},
publish=#{publish}, ISBN=#{ISBN}, introduction=#{introduction},
language=#{language}, price=#{price}, pub_date=#{pub_date},
class_id=#{class_id}, number=#{number} where book_id=#{book_id}
</update>
<select id="getAllBooks" resultType="com.library.bean.Book">
select * from book_info
</select>
<select id="queryBook" resultType="com.library.bean.Book" parameterType="String">
select * from book_info where name like #{search}
or author like #{search} or introduction like #{search}
</select>
<select id="matchBook" resultType="int" parameterType="String">
select count(*) from book_info where name like #{search}
or author like #{search} or introduction like #{search}
</select>
<select id="getBook" resultType="com.library.bean.Book" parameterType="long">
select * from book_info where book_id = #{book_id}
</select>
<delete id="deleteBook" parameterType="long">
delete from book_info where book_id = #{book_id}
</delete>
</mapper>
42 changes: 42 additions & 0 deletions src/main/resources/MyBatis/lend.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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.library.dao.LendDao">

private final static String RETURN_BOOK_ONE_SQL = "UPDATE lend_list SET back_date = ? WHERE book_id = ? AND
reader_id = ? AND back_date is NULL";
private final static String RETURN_BOOK_TWO_SQL = "UPDATE book_info SET number = number + 1 WHERE book_id = ? ";
private final static String LEND_BOOK_ONE_SQL = "INSERT INTO lend_list VALUES (NULL , ? , ? , ? , NULL)";
private final static String LEND_BOOK_TWO_SQL = "UPDATE book_info SET number = number - 1 WHERE book_id = ? ";
private final static String LEND_LIST_SQL = "SELECT * FROM lend_list";
private final static String MY_LEND_LIST_SQL = "SELECT * FROM lend_list WHERE reader_id = ? ";
private final static String DELETE_LEND_SQL = "DELETE FROM lend_list WHERE ser_num = ?";

<update id="returnBookOne" parameterType="com.library.bean.Book">
update lend_list set back_date = ? where book_id = ? AND reader_id = ? AND back_date is NULL";
</update>


<update id="editBook" parameterType="com.library.bean.Book">
update book_info set name=#{name}, author=#{author},
publish=#{publish}, ISBN=#{ISBN}, introduction=#{introduction},
language=#{language}, price=#{price}, pub_date=#{pub_date},
class_id=#{class_id}, number=#{number} where book_id=#{book_id}
</update>
<select id="getAllBooks" resultType="com.library.bean.Book">
select * from book_info
</select>
<select id="queryBook" resultType="com.library.bean.Book" parameterType="String">
select * from book_info where name like #{search}
or author like #{search} or introduction like #{search}
</select>
<select id="matchBook" resultType="int" parameterType="String">
select count(*) from book_info where name like #{search}
or author like #{search} or introduction like #{search}
</select>
<select id="getBook" resultType="com.library.bean.Book" parameterType="long">
select * from book_info where book_id = #{book_id}
</select>
<delete id="deleteBook" parameterType="long">
delete from book_info where book_id = #{book_id}
</delete>
</mapper>
5 changes: 5 additions & 0 deletions src/main/resources/db.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#mysql jdbc
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/library?useUnicode=true&characterEncoding=UTF-8
jdbc.username=root
jdbc.password=123456

0 comments on commit 9f7f969

Please sign in to comment.