From 896fff6ed9369aeb3180336092b7efe5644de7ad Mon Sep 17 00:00:00 2001 From: zz <193970753@qq.com> Date: Mon, 16 Sep 2024 00:19:12 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=AC=A1=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springboot/task1/User.java | 4 ++ .../task1/controller/bookController.java | 23 ++++++++++ .../task1/controller/reviewController.java | 43 +++++++++++++++++++ .../springboot/task1/dao/BookMapper.java | 4 ++ .../springboot/task1/dao/BorrowMapper.java | 19 ++++++++ .../springboot/task1/dao/ReviewMapper.java | 15 +++++++ .../task1/dao/impl/BookServiceImpl.java | 14 ++++++ .../task1/dao/impl/BorrowServiceImpl.java | 35 +++++++++++++++ .../task1/dao/impl/ReviewServiceImpl.java | 25 +++++++++++ .../springboot/task1/model/BorrowRecord.java | 11 +++++ .../springboot/task1/model/Review.java | 11 +++++ .../springboot/task1/model/User.java | 1 + .../springboot/task1/service/BookService.java | 14 +++++- .../task1/service/BorrowService.java | 18 ++++++++ .../task1/service/ReviewService.java | 14 ++++++ .../main/resources/mapper/BorrowMapper.xml | 34 +++++++++++++++ .../main/resources/mapper/ReviewMapper.xml | 13 ++++++ .../main/resources/templates/addreview.html | 16 +++++++ .../main/resources/templates/bookdetail.html | 12 ++++++ .../main/resources/templates/borrowbook.html | 15 +++++++ .../main/resources/templates/borrowlist.html | 32 ++++++++++++++ .../resources/templates/borrowlistnull.html | 11 +++++ .../resources/templates/borrowsuccess.html | 11 +++++ .../main/resources/templates/deletebook.html | 13 ++++++ .../main/resources/templates/reviewlist.html | 25 +++++++++++ .../main/resources/templates/updatebook.html | 19 ++++++++ .../resources/templates/updateborrow.html | 16 +++++++ .../task1/Task1ApplicationTests.java | 0 28 files changed, 466 insertions(+), 2 deletions(-) create mode 100644 task1/src/main/java/com/zzh202101080104/springboot/task1/User.java create mode 100644 task1/src/main/java/com/zzh202101080104/springboot/task1/controller/reviewController.java create mode 100644 task1/src/main/java/com/zzh202101080104/springboot/task1/dao/BorrowMapper.java create mode 100644 task1/src/main/java/com/zzh202101080104/springboot/task1/dao/ReviewMapper.java create mode 100644 task1/src/main/java/com/zzh202101080104/springboot/task1/dao/impl/BorrowServiceImpl.java create mode 100644 task1/src/main/java/com/zzh202101080104/springboot/task1/dao/impl/ReviewServiceImpl.java create mode 100644 task1/src/main/java/com/zzh202101080104/springboot/task1/model/BorrowRecord.java create mode 100644 task1/src/main/java/com/zzh202101080104/springboot/task1/model/Review.java create mode 100644 task1/src/main/java/com/zzh202101080104/springboot/task1/service/BorrowService.java create mode 100644 task1/src/main/java/com/zzh202101080104/springboot/task1/service/ReviewService.java create mode 100644 task1/src/main/resources/mapper/BorrowMapper.xml create mode 100644 task1/src/main/resources/mapper/ReviewMapper.xml create mode 100644 task1/src/main/resources/templates/addreview.html create mode 100644 task1/src/main/resources/templates/bookdetail.html create mode 100644 task1/src/main/resources/templates/borrowbook.html create mode 100644 task1/src/main/resources/templates/borrowlist.html create mode 100644 task1/src/main/resources/templates/borrowlistnull.html create mode 100644 task1/src/main/resources/templates/borrowsuccess.html create mode 100644 task1/src/main/resources/templates/deletebook.html create mode 100644 task1/src/main/resources/templates/reviewlist.html create mode 100644 task1/src/main/resources/templates/updatebook.html create mode 100644 task1/src/main/resources/templates/updateborrow.html rename task1/src/test/java/com/{zyx202101080136 => zzh202101080104}/springboot/task1/Task1ApplicationTests.java (100%) diff --git a/task1/src/main/java/com/zzh202101080104/springboot/task1/User.java b/task1/src/main/java/com/zzh202101080104/springboot/task1/User.java new file mode 100644 index 0000000..c3ad187 --- /dev/null +++ b/task1/src/main/java/com/zzh202101080104/springboot/task1/User.java @@ -0,0 +1,4 @@ +package com.zzh202101080104.springboot.task1; + +public class User { +} diff --git a/task1/src/main/java/com/zzh202101080104/springboot/task1/controller/bookController.java b/task1/src/main/java/com/zzh202101080104/springboot/task1/controller/bookController.java index 7ceefbb..3a74787 100644 --- a/task1/src/main/java/com/zzh202101080104/springboot/task1/controller/bookController.java +++ b/task1/src/main/java/com/zzh202101080104/springboot/task1/controller/bookController.java @@ -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"; + } } + + + diff --git a/task1/src/main/java/com/zzh202101080104/springboot/task1/controller/reviewController.java b/task1/src/main/java/com/zzh202101080104/springboot/task1/controller/reviewController.java new file mode 100644 index 0000000..9e5a24d --- /dev/null +++ b/task1/src/main/java/com/zzh202101080104/springboot/task1/controller/reviewController.java @@ -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 reviewlist=reviewService.listReviewByBookId(bookid); + model.addAttribute("reviewlist",reviewlist); + if(reviewlist.size()>0){ + return "reviewlist.html"; + }else { + return "noreview.html"; + } + } +} diff --git a/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/BookMapper.java b/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/BookMapper.java index d229c6a..036e577 100644 --- a/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/BookMapper.java +++ b/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/BookMapper.java @@ -9,4 +9,8 @@ import java.util.List; public interface BookMapper { public List getBooks(); public int addBook(Book book); + public int updateBookById(Book book); + + + public int deleteBookById(int id); } diff --git a/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/BorrowMapper.java b/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/BorrowMapper.java new file mode 100644 index 0000000..8e02008 --- /dev/null +++ b/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/BorrowMapper.java @@ -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 getBorrowRecordById(int id); + // 根据书籍id删除借阅记录 + public int deleteBorrowRecordById(int id); + // 根据记录id修改借阅记录 + public int updateBorrowRecordById(BorrowRecord borrowRecord); +} diff --git a/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/ReviewMapper.java b/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/ReviewMapper.java new file mode 100644 index 0000000..cfc0e3f --- /dev/null +++ b/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/ReviewMapper.java @@ -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 listReviewByBookId(int bookid); +} diff --git a/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/impl/BookServiceImpl.java b/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/impl/BookServiceImpl.java index 8c5f464..8e523af 100644 --- a/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/impl/BookServiceImpl.java +++ b/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/impl/BookServiceImpl.java @@ -19,9 +19,23 @@ public class BookServiceImpl implements BookService { return bookMapper.getBooks(); } + @Override + public List 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); + } } diff --git a/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/impl/BorrowServiceImpl.java b/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/impl/BorrowServiceImpl.java new file mode 100644 index 0000000..db1186f --- /dev/null +++ b/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/impl/BorrowServiceImpl.java @@ -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 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); + } +} \ No newline at end of file diff --git a/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/impl/ReviewServiceImpl.java b/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/impl/ReviewServiceImpl.java new file mode 100644 index 0000000..a31c5d2 --- /dev/null +++ b/task1/src/main/java/com/zzh202101080104/springboot/task1/dao/impl/ReviewServiceImpl.java @@ -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 listReviewByBookId(int bookid) { + return reviewMapper.listReviewByBookId(bookid); + } +} diff --git a/task1/src/main/java/com/zzh202101080104/springboot/task1/model/BorrowRecord.java b/task1/src/main/java/com/zzh202101080104/springboot/task1/model/BorrowRecord.java new file mode 100644 index 0000000..4ad7f7b --- /dev/null +++ b/task1/src/main/java/com/zzh202101080104/springboot/task1/model/BorrowRecord.java @@ -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; +} \ No newline at end of file diff --git a/task1/src/main/java/com/zzh202101080104/springboot/task1/model/Review.java b/task1/src/main/java/com/zzh202101080104/springboot/task1/model/Review.java new file mode 100644 index 0000000..d975988 --- /dev/null +++ b/task1/src/main/java/com/zzh202101080104/springboot/task1/model/Review.java @@ -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; +} diff --git a/task1/src/main/java/com/zzh202101080104/springboot/task1/model/User.java b/task1/src/main/java/com/zzh202101080104/springboot/task1/model/User.java index 0087eef..1241fe4 100644 --- a/task1/src/main/java/com/zzh202101080104/springboot/task1/model/User.java +++ b/task1/src/main/java/com/zzh202101080104/springboot/task1/model/User.java @@ -4,6 +4,7 @@ import lombok.Data; //Data自动生成set get 方法 @Data public class User { + private int id; private String username; private String password; diff --git a/task1/src/main/java/com/zzh202101080104/springboot/task1/service/BookService.java b/task1/src/main/java/com/zzh202101080104/springboot/task1/service/BookService.java index 83e69cc..a7925be 100644 --- a/task1/src/main/java/com/zzh202101080104/springboot/task1/service/BookService.java +++ b/task1/src/main/java/com/zzh202101080104/springboot/task1/service/BookService.java @@ -5,6 +5,16 @@ import com.zzh202101080104.springboot.task1.model.Book; import java.util.List; public interface BookService { - public List getBooks(); + // 查找所有书籍 + public List listBook(); + // 添加书籍 public int addBook(Book book); -} + + // 根据id修改书籍信息 + public int updateBookById(Book book); + + // 删除书籍信息 + public int deleteBookById(int id); + + List getBooks(); +} \ No newline at end of file diff --git a/task1/src/main/java/com/zzh202101080104/springboot/task1/service/BorrowService.java b/task1/src/main/java/com/zzh202101080104/springboot/task1/service/BorrowService.java new file mode 100644 index 0000000..7e41cb4 --- /dev/null +++ b/task1/src/main/java/com/zzh202101080104/springboot/task1/service/BorrowService.java @@ -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 getBorrowRecordById(int id); + // 根据书籍id删除借阅记录 + public int deleteBorrowRecordById(int id); + // 根据记录id修改借阅记录 + public int updateBorrowRecordById(BorrowRecord borrowRecord); +} diff --git a/task1/src/main/java/com/zzh202101080104/springboot/task1/service/ReviewService.java b/task1/src/main/java/com/zzh202101080104/springboot/task1/service/ReviewService.java new file mode 100644 index 0000000..cf1698e --- /dev/null +++ b/task1/src/main/java/com/zzh202101080104/springboot/task1/service/ReviewService.java @@ -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 listReviewByBookId(int bookid); +} diff --git a/task1/src/main/resources/mapper/BorrowMapper.xml b/task1/src/main/resources/mapper/BorrowMapper.xml new file mode 100644 index 0000000..f009eb0 --- /dev/null +++ b/task1/src/main/resources/mapper/BorrowMapper.xml @@ -0,0 +1,34 @@ + + + + + insert into borrow_records202101080142(bookid,userid) + values(#{bookid},#{userid}) + + + + + + + + + + + + + + delete from borrow_records202101080142 where id=#{id} + + + + update borrow_records202101080142 + set bookid=#{bookid},userid=#{userid} + where id=#{id} + + \ No newline at end of file diff --git a/task1/src/main/resources/mapper/ReviewMapper.xml b/task1/src/main/resources/mapper/ReviewMapper.xml new file mode 100644 index 0000000..69d6ed0 --- /dev/null +++ b/task1/src/main/resources/mapper/ReviewMapper.xml @@ -0,0 +1,13 @@ + + + + + + + insert into reviews202101080142(bookid,userid,reviewsinfo) + values(#{bookid},#{userid},#{reviewsinfo}) + + diff --git a/task1/src/main/resources/templates/addreview.html b/task1/src/main/resources/templates/addreview.html new file mode 100644 index 0000000..acb832f --- /dev/null +++ b/task1/src/main/resources/templates/addreview.html @@ -0,0 +1,16 @@ + + + + + 添加评论 + + +

添加评论

+
+ 书籍id:
+ 评论人id:
+ 请输入评论:
+ +
+ + \ No newline at end of file diff --git a/task1/src/main/resources/templates/bookdetail.html b/task1/src/main/resources/templates/bookdetail.html new file mode 100644 index 0000000..6b1cbce --- /dev/null +++ b/task1/src/main/resources/templates/bookdetail.html @@ -0,0 +1,12 @@ + + + + + 书籍详情 + + + + + + + diff --git a/task1/src/main/resources/templates/borrowbook.html b/task1/src/main/resources/templates/borrowbook.html new file mode 100644 index 0000000..b826ddf --- /dev/null +++ b/task1/src/main/resources/templates/borrowbook.html @@ -0,0 +1,15 @@ + + + + + 借阅书籍 + + +

借阅书籍

+
+ 书籍id:
+ 借阅人id:
+ +
+ + \ No newline at end of file diff --git a/task1/src/main/resources/templates/borrowlist.html b/task1/src/main/resources/templates/borrowlist.html new file mode 100644 index 0000000..8110349 --- /dev/null +++ b/task1/src/main/resources/templates/borrowlist.html @@ -0,0 +1,32 @@ + + + + + 借阅记录 + + +

借阅记录

+ + + + + + + + + + + + + + + + + +
id书籍id借阅者id借阅者更新借阅信息删除借阅信息
+ 更新 + + 删除 +
+ + \ No newline at end of file diff --git a/task1/src/main/resources/templates/borrowlistnull.html b/task1/src/main/resources/templates/borrowlistnull.html new file mode 100644 index 0000000..43f5202 --- /dev/null +++ b/task1/src/main/resources/templates/borrowlistnull.html @@ -0,0 +1,11 @@ + + + + + 借阅记录 + + +

该书籍暂无借阅记录

+返回书籍列表 + + \ No newline at end of file diff --git a/task1/src/main/resources/templates/borrowsuccess.html b/task1/src/main/resources/templates/borrowsuccess.html new file mode 100644 index 0000000..f67f43e --- /dev/null +++ b/task1/src/main/resources/templates/borrowsuccess.html @@ -0,0 +1,11 @@ + + + + + 借阅书籍 + + +

借阅成功

+ 返回书籍列表 + + \ No newline at end of file diff --git a/task1/src/main/resources/templates/deletebook.html b/task1/src/main/resources/templates/deletebook.html new file mode 100644 index 0000000..81b60b6 --- /dev/null +++ b/task1/src/main/resources/templates/deletebook.html @@ -0,0 +1,13 @@ + + + + + 删除书籍 + + +
+
+ +
+ + \ No newline at end of file diff --git a/task1/src/main/resources/templates/reviewlist.html b/task1/src/main/resources/templates/reviewlist.html new file mode 100644 index 0000000..f22a5ca --- /dev/null +++ b/task1/src/main/resources/templates/reviewlist.html @@ -0,0 +1,25 @@ + + + + + 书籍评论页面 + + +

书籍评论页面

+ + + + + + + + + + + + + + +
id书籍id评论者id评论内容
+ + \ No newline at end of file diff --git a/task1/src/main/resources/templates/updatebook.html b/task1/src/main/resources/templates/updatebook.html new file mode 100644 index 0000000..914cbdf --- /dev/null +++ b/task1/src/main/resources/templates/updatebook.html @@ -0,0 +1,19 @@ + + + + + 更新书籍信息 + + +

更新书籍信息

+
+ id:
+ 书名:
+ 作者:
+ isbn号:
+ 出版方:
+ 出版时间:
+ +
+ + \ No newline at end of file diff --git a/task1/src/main/resources/templates/updateborrow.html b/task1/src/main/resources/templates/updateborrow.html new file mode 100644 index 0000000..6005350 --- /dev/null +++ b/task1/src/main/resources/templates/updateborrow.html @@ -0,0 +1,16 @@ + + + + + 更新借阅信息 + + +

更新借阅信息

+
+ id:
+ 书籍id:
+ 借阅者id:
+ +
+ + \ No newline at end of file diff --git a/task1/src/test/java/com/zyx202101080136/springboot/task1/Task1ApplicationTests.java b/task1/src/test/java/com/zzh202101080104/springboot/task1/Task1ApplicationTests.java similarity index 100% rename from task1/src/test/java/com/zyx202101080136/springboot/task1/Task1ApplicationTests.java rename to task1/src/test/java/com/zzh202101080104/springboot/task1/Task1ApplicationTests.java