第三次作业提交

This commit is contained in:
zz 2024-09-16 00:19:12 +08:00
parent 811d23b778
commit 896fff6ed9
28 changed files with 466 additions and 2 deletions

View File

@ -0,0 +1,4 @@
package com.zzh202101080104.springboot.task1;
public class User {
}

View File

@ -36,5 +36,28 @@ public class bookController {
bookService.addBook(book);
return "redirect:bookList";
}
// 跳转至更新书籍页面
@RequestMapping("updatebook")
public String updateperson(Book book,Model model){
//todo 显示修改页面
model.addAttribute("book",book);
return "updatebook.html";
}
// 根据id更新书籍信息
@RequestMapping("updatebookcommit")
public String updateBookCommit(Book book) {
bookService.updateBookById(book);
return "redirect:booklist";
}
// 删除书籍信息
@RequestMapping("deletebook")
public String deleteBook(Integer id) {
bookService.deleteBookById(id);
return "redirect:booklist";
}
}

View File

@ -0,0 +1,43 @@
package com.zzh202101080104.springboot.task1.controller;
import com.zzh202101080104.springboot.task1.model.Review;
import com.zzh202101080104.springboot.task1.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
@Controller
public class reviewController {
@Autowired
ReviewService reviewService;
// 进入评论页面
@RequestMapping("addreview")
public String addReview(Model model,int bookid){
model.addAttribute("bookid",bookid);
return "addreview.html";
}
// 提交评论
@RequestMapping("addreviewcommit")
public String addReviewCommit(Review review){
reviewService.addReview(review);
return "redirect:booklist";
}
// 根据id查找评论
@RequestMapping("reviewlist")
public String reviewlist(Model model,int bookid){
List<Review> reviewlist=reviewService.listReviewByBookId(bookid);
model.addAttribute("reviewlist",reviewlist);
if(reviewlist.size()>0){
return "reviewlist.html";
}else {
return "noreview.html";
}
}
}

View File

@ -9,4 +9,8 @@ import java.util.List;
public interface BookMapper {
public List<Book> getBooks();
public int addBook(Book book);
public int updateBookById(Book book);
public int deleteBookById(int id);
}

View File

@ -0,0 +1,19 @@
package com.zzh202101080104.springboot.task1.dao;
import com.zzh202101080104.springboot.task1.model.BorrowRecord;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface BorrowMapper {
// 增加借阅记录
public int addBorrowRecord(BorrowRecord borrowRecord);
// 根据id查找书籍借阅记录
public List<BorrowRecord> getBorrowRecordById(int id);
// 根据书籍id删除借阅记录
public int deleteBorrowRecordById(int id);
// 根据记录id修改借阅记录
public int updateBorrowRecordById(BorrowRecord borrowRecord);
}

View File

@ -0,0 +1,15 @@
package com.zzh202101080104.springboot.task1.dao;
import com.zzh202101080104.springboot.task1.model.Review;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface ReviewMapper {
// 增加评论
public int addReview(Review review);
// 根据书籍id查找评论
public List<Review> listReviewByBookId(int bookid);
}

View File

@ -19,9 +19,23 @@ public class BookServiceImpl implements BookService {
return bookMapper.getBooks();
}
@Override
public List<Book> listBook() {
return List.of();
}
@Override
public int addBook(Book book) {
return bookMapper.addBook(book);
}
@Override
public int updateBookById(Book book) {
return bookMapper.updateBookById(book);
}
@Override
public int deleteBookById(int id) {
return bookMapper.deleteBookById(id);
}
}

View File

@ -0,0 +1,35 @@
package com.zzh202101080104.springboot.task1.dao.impl;
import com.zzh202101080104.springboot.task1.dao.BorrowMapper;
import com.zzh202101080104.springboot.task1.model.BorrowRecord;
import com.zzh202101080104.springboot.task1.service.BorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class BorrowServiceImpl implements BorrowService {
@Autowired
BorrowMapper borrowMapper;
@Override
public int addBorrowRecord(BorrowRecord borrowRecord) {
return borrowMapper.addBorrowRecord(borrowRecord);
}
@Override
public List<BorrowRecord> getBorrowRecordById(int id) {
return borrowMapper.getBorrowRecordById(id);
}
@Override
public int deleteBorrowRecordById(int id) {
return borrowMapper.deleteBorrowRecordById(id);
}
@Override
public int updateBorrowRecordById(BorrowRecord borrowRecord) {
return borrowMapper.updateBorrowRecordById(borrowRecord);
}
}

View File

@ -0,0 +1,25 @@
package com.zzh202101080104.springboot.task1.dao.impl;
import com.zzh202101080104.springboot.task1.dao.ReviewMapper;
import com.zzh202101080104.springboot.task1.model.Review;
import com.zzh202101080104.springboot.task1.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ReviewServiceImpl implements ReviewService {
@Autowired
ReviewMapper reviewMapper;
@Override
public int addReview(Review review) {
return reviewMapper.addReview(review);
}
@Override
public List<Review> listReviewByBookId(int bookid) {
return reviewMapper.listReviewByBookId(bookid);
}
}

View File

@ -0,0 +1,11 @@
package com.zzh202101080104.springboot.task1.model;
import lombok.Data;
@Data
public class BorrowRecord {
private int id;
private int bookid;
private int userid;
private User user;
}

View File

@ -0,0 +1,11 @@
package com.zzh202101080104.springboot.task1.model;
import lombok.Data;
@Data
public class Review {
private int id;
private int bookid;
private int userid;
private String reviewsinfo;
}

View File

@ -4,6 +4,7 @@ import lombok.Data;
//Data自动生成set get 方法
@Data
public class User {
private int id;
private String username;
private String password;

View File

@ -5,6 +5,16 @@ import com.zzh202101080104.springboot.task1.model.Book;
import java.util.List;
public interface BookService {
public List<Book> getBooks();
// 查找所有书籍
public List<Book> listBook();
// 添加书籍
public int addBook(Book book);
}
// 根据id修改书籍信息
public int updateBookById(Book book);
// 删除书籍信息
public int deleteBookById(int id);
List<Book> getBooks();
}

View File

@ -0,0 +1,18 @@
package com.zzh202101080104.springboot.task1.service;
import com.zzh202101080104.springboot.task1.model.BorrowRecord;
import java.util.List;
public interface BorrowService {
// 增加借阅记录
public int addBorrowRecord(BorrowRecord borrowRecord);
// 根据id查找书籍借阅记录
public List<BorrowRecord> getBorrowRecordById(int id);
// 根据书籍id删除借阅记录
public int deleteBorrowRecordById(int id);
// 根据记录id修改借阅记录
public int updateBorrowRecordById(BorrowRecord borrowRecord);
}

View File

@ -0,0 +1,14 @@
package com.zzh202101080104.springboot.task1.service;
import com.zzh202101080104.springboot.task1.model.Review;
import java.util.List;
public interface ReviewService {
// 增加评论
public int addReview(Review review);
// 根据书籍id查找评论
public List<Review> listReviewByBookId(int bookid);
}

View File

@ -0,0 +1,34 @@
<?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.zzh202101080104.springboot.task1.dao.BorrowMapper">
<insert id="addBorrowRecord" parameterType="com.zzh202101080104.springboot.task1.model.BorrowRecord">
insert into borrow_records202101080142(bookid,userid)
values(#{bookid},#{userid})
</insert>
<select id="getBorrowRecordById" resultMap="borrowRecordMap">
select * from borrow_records202101080104
where bookid=#{bookid}
</select>
<resultMap id="borrowRecordMap" type="com.zzh202101080104.springboot.task1.model.BorrowRecord">
<id property="id" column="id"/>
<result property="bookid" column="bookid"/>
<result property="userid" column="userid"/>
<association property="user" javaType="com.zzh202101080104.springboot.task1.User"
column="userid" select="">
</association>
</resultMap>
<!--根据书籍id删除借阅记录-->
<delete id="deleteBorrowRecordById" parameterType="integer">
delete from borrow_records202101080142 where id=#{id}
</delete>
<!--根据记录id修改借阅记录-->
<update id="updateBorrowRecordById" parameterType="com.zzh202101080104.springboot.task1.model.BorrowRecord">
update borrow_records202101080142
set bookid=#{bookid},userid=#{userid}
where id=#{id}
</update>
</mapper>

View File

@ -0,0 +1,13 @@
<?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.zzh202101080104.springboot.task1.dao.UserMapper">
<select id="listReviewByBookId" resultType="com.zzh202101080104.springboot.task1.model.Review">
select * from reviews202101080142
where bookid=#{bookid}
</select>
<!--增加书籍-->
<insert id="addReview" parameterType="com.zzh202101080104.springboot.task1.model.Review">
insert into reviews202101080142(bookid,userid,reviewsinfo)
values(#{bookid},#{userid},#{reviewsinfo})
</insert>
</mapper>

View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>添加评论</title>
</head>
<body>
<h1>添加评论</h1>
<form th:action="@{/addreviewcommit}" method="post">
书籍id<input type="text" name="bookid" th:value="${bookid}" readonly="readonly"><br/></input>
评论人id<input type="text" name="userid" placeholder="请填写您的id"><br/></input>
请输入评论:<input type="text" name="reviewsinfo" placeholder="请文明评论"><br/>
<input type="submit" value="提交">
</form>
</body>
</html>

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>书籍详情</title>
</head>
<body>
<input th:href="@{/addbook}" type="submit" value="添加书籍">
</body>
</html>

View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>借阅书籍</title>
</head>
<body>
<h1>借阅书籍</h1>
<form th:action="@{/borrowbookcommit}" method="post">
书籍id<input type="text" name="bookid" th:value="${bookid}" readonly="readonly"><br/></input>
借阅人id<input type="text" name="userid" placeholder="请填写您的id"><br/></input>
<input type="submit" value="提交">
</form>
</body>
</html>

View File

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>借阅记录</title>
</head>
<body>
<h1>借阅记录</h1>
<table border="1">
<tr>
<td>id</td>
<td>书籍id</td>
<td>借阅者id</td>
<td>借阅者</td>
<td>更新借阅信息</td>
<td>删除借阅信息</td>
</tr>
<tr th:each="borrowlist:${borrowlist}">
<td th:text="${borrowlist.id}"></td>
<td th:text="${borrowlist.bookid}"></td>
<td th:text="${borrowlist.userid}"></td>
<td th:text="${borrowlist.user.username}"></td>
<td>
<a th:href="@{/updateborrow(id=${borrowlist.id},bookid=${borrowlist.bookid},userid=${borrowlist.userid} )}">更新</a>
</td>
<td>
<a th:href="@{/deleteborrow(id=${borrowlist.id},bookid=${borrowlist.bookid}) }">删除</a>
</td>
</tr>
</table>
</body>
</html>

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>借阅记录</title>
</head>
<body>
<h1>该书籍暂无借阅记录</h1>
<a href="/booklist">返回书籍列表</a>
</body>
</html>

View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>借阅书籍</title>
</head>
<body>
<h1>借阅成功</h1>
<a href="/booklist">返回书籍列表</a>
</body>
</html>

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>删除书籍</title>
</head>
<body>
<form th:action="@{/deletebookcommit}" method="post">
<input type="text" name="id" placeholder="书籍id"><br/>
<input type="submit" value="删除">
</form>
</body>
</html>

View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>书籍评论页面</title>
</head>
<body>
<h1>书籍评论页面</h1>
<table border="1">
<tr>
<td>id</td>
<td>书籍id</td>
<td>评论者id</td>
<td>评论内容</td>
</tr>
<tr th:each="reviewlist:${reviewlist}">
<td th:text="${reviewlist.id}"></td>
<td th:text="${reviewlist.bookid}"></td>
<td th:text="${reviewlist.userid}"></td>
<td th:text="${reviewlist.reviewsinfo}"></td>
</tr>
</table>
</body>
</html>

View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>更新书籍信息</title>
</head>
<body>
<h1>更新书籍信息</h1>
<form th:action="@{/updatebookcommit}" method="post">
id<input type="text" name="id" th:value="${book.id}" readonly="readonly"><br/>
书名:<input type="text" name="title" th:value="${book.title}"><br/>
作者:<input type="text" name="author" th:value="${book.author}"><br/>
isbn号<input type="text" name="isbn" th:value="${book.isbn}"><br/>
出版方:<input type="text" name="publisher" th:value="${book.publisher}"><br/>
出版时间:<input type="text" name="published_date" th:value="${book.published_date}"><br/>
<input type="submit" value="更新">
</form>
</body>
</html>

View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>更新借阅信息</title>
</head>
<body>
<h1>更新借阅信息</h1>
<form th:action="@{/updateborrowcommit}" method="post">
id<input type="text" name="id" th:value="${borrowRecord.id}" readonly="readonly"><br/>
书籍id<input type="text" name="bookid" th:value="${borrowRecord.bookid}"><br/>
借阅者id<input type="text" name="userid" th:value="${borrowRecord.userid}"><br/>
<input type="submit" value="更新">
</form>
</body>
</html>