From 9a244f8efde7ed569a2f2d7bc714f155653bcc2e Mon Sep 17 00:00:00 2001
From: adan <3126044859@qq.com>
Date: Mon, 11 Nov 2024 01:32:03 +0800
Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E5=9B=9B=E6=AC=A1=E4=BD=9C=E4=B8=9A?=
=?UTF-8?q?=E5=90=8E=E7=AB=AF=E4=BB=A3=E7=A0=81=EF=BC=88=E6=9C=AA=E5=AE=8C?=
=?UTF-8?q?=E6=88=90=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Books202201020417Controller.java | 56 ++++++++++++++++++
.../task1/controller/BooksController.java | 51 +++++++++++++++-
.../task1/controller/BorrowController.java | 12 ++++
.../task1/controller/ReviewsController.java | 4 +-
.../task1/dao/Books202201020417Mapper.java | 19 ++++++
.../c202201020417/task1/dao/BooksMapper.java | 1 +
.../task1/dao/ReviewsMapper.java | 2 +-
.../com/c202201020417/task1/model/Books.java | 6 +-
.../task1/model/Books202201020417.java | 39 +++++++++++++
.../com/c202201020417/task1/model/Result.java | 58 +++++++++++++++++++
.../task1/service/BooksService.java | 4 ++
.../service/IBooks202201020417Service.java | 19 ++++++
.../impl/Books202201020417ServiceImpl.java | 30 ++++++++++
.../task1/service/impl/BooksServiceImpl.java | 7 ++-
.../service/impl/ReviewsServiceImpl.java | 6 +-
.../mapper/Books202201020417Mapper.xml | 5 ++
src/main/resources/mapper/BooksMapper.xml | 1 +
17 files changed, 309 insertions(+), 11 deletions(-)
create mode 100644 src/main/java/com/c202201020417/task1/controller/Books202201020417Controller.java
create mode 100644 src/main/java/com/c202201020417/task1/dao/Books202201020417Mapper.java
create mode 100644 src/main/java/com/c202201020417/task1/model/Books202201020417.java
create mode 100644 src/main/java/com/c202201020417/task1/model/Result.java
create mode 100644 src/main/java/com/c202201020417/task1/service/IBooks202201020417Service.java
create mode 100644 src/main/java/com/c202201020417/task1/service/impl/Books202201020417ServiceImpl.java
create mode 100644 src/main/resources/mapper/Books202201020417Mapper.xml
diff --git a/src/main/java/com/c202201020417/task1/controller/Books202201020417Controller.java b/src/main/java/com/c202201020417/task1/controller/Books202201020417Controller.java
new file mode 100644
index 0000000..b6be1e2
--- /dev/null
+++ b/src/main/java/com/c202201020417/task1/controller/Books202201020417Controller.java
@@ -0,0 +1,56 @@
+package com.c202201020417.task1.controller;
+
+import com.c202201020417.task1.model.Books;
+import com.c202201020417.task1.model.Books202201020417;
+import com.c202201020417.task1.model.Result;
+import com.c202201020417.task1.model.Reviews;
+import com.c202201020417.task1.service.IBooks202201020417Service;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import java.util.List;
+
+/**
+ *
+ * 前端控制器
+ *
+ *
+ * @author 张三
+ * @since 2024-10-13
+ */
+@CrossOrigin
+@Controller
+@RequestMapping("/books202201020417")
+public class Books202201020417Controller {
+ @Autowired
+ IBooks202201020417Service books202201020417Service;
+ @ResponseBody
+ @RequestMapping("/getBooks")
+ public Result getBooks(){
+ List books202201020417List = books202201020417Service.list();
+ return Result.ok().put("data", books202201020417List);
+ }
+ @ResponseBody
+ @RequestMapping("/addBooks")
+ public Result addBooks(Books202201020417 book202201120417 ){
+ /*iStudentService.list();*/
+ boolean result = books202201020417Service.saveOrUpdate(book202201120417);
+ if(result){
+ return Result.ok();
+ }
+ return Result.error();
+ }
+ @ResponseBody
+ @RequestMapping("/deleteBooks")
+ public Result deleteBook(int id){
+ /*iStudentService.list();*/
+ boolean result = books202201020417Service.removeById(id);
+ if(result){
+ return Result.ok();
+ }
+ return Result.error();
+ }
+}
diff --git a/src/main/java/com/c202201020417/task1/controller/BooksController.java b/src/main/java/com/c202201020417/task1/controller/BooksController.java
index 034e377..b6e4f27 100644
--- a/src/main/java/com/c202201020417/task1/controller/BooksController.java
+++ b/src/main/java/com/c202201020417/task1/controller/BooksController.java
@@ -1,13 +1,17 @@
package com.c202201020417.task1.controller;
import com.c202201020417.task1.model.Books;
+import com.c202201020417.task1.model.Result;
import com.c202201020417.task1.model.Reviews;
import com.c202201020417.task1.service.BooksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+@CrossOrigin
@Controller
public class BooksController {
@Autowired
@@ -17,8 +21,13 @@ public class BooksController {
model.addAttribute("booksList",booksService.getAllBook());
return "bookpage.html";
}
+ @ResponseBody
+ @RequestMapping("/getbooks1")
+ public Result getbooks1(){
+ return Result.ok().put("data",booksService.getAllBook());
+ }
@RequestMapping("/addbook")
- public String addbook(Books books){
+ public String addbook(){
return "addbookpage.html";
}
@RequestMapping("/addbookcommit")
@@ -26,11 +35,31 @@ public class BooksController {
booksService.addBook(books);
return "redirect:/bookpage";
}
+ @ResponseBody
+ @RequestMapping("/addbookcommit1")
+ public Result addbookcommit1(Books book){
+ int result = booksService.addBook(book);
+ if (result>=1){
+ return Result.ok();
+ }else {
+ return Result.error();
+ }
+ }
@RequestMapping("/deletebook")
public String deletebook(int id){
booksService.deleteBook(id);
return "redirect:/bookpage";
}
+ @ResponseBody
+ @RequestMapping("/deletebook1")
+ public Result deletebook1(int id){
+ int result = booksService.deleteBook(id);
+ if (result>=1){
+ return Result.ok();
+ }else {
+ return Result.error();
+ }
+ }
@RequestMapping("/updatebook")
public String updatebook(Books books,Model model){
model.addAttribute("books",books);
@@ -41,5 +70,25 @@ public class BooksController {
booksService.updateBook(books);
return "redirect:/bookpage";
}
+ @ResponseBody
+ @RequestMapping("/updatebookcommit1")
+ public Result updatebookcommit1(Books books){
+ int result = booksService.updateBook(books);
+ if (result>=1){
+ return Result.ok();
+ }else {
+ return Result.error();
+ }
+ }
+ @ResponseBody
+ @RequestMapping("/addreview1")
+ public Result addreview1(Reviews reviews){
+ int result = booksService.addReview(reviews);
+ if (result>=1){
+ return Result.ok();
+ }else {
+ return Result.error();
+ }
+ }
}
diff --git a/src/main/java/com/c202201020417/task1/controller/BorrowController.java b/src/main/java/com/c202201020417/task1/controller/BorrowController.java
index 95073c5..e9c38df 100644
--- a/src/main/java/com/c202201020417/task1/controller/BorrowController.java
+++ b/src/main/java/com/c202201020417/task1/controller/BorrowController.java
@@ -2,12 +2,14 @@ package com.c202201020417.task1.controller;
import com.c202201020417.task1.model.Books;
import com.c202201020417.task1.model.Borrow;
+import com.c202201020417.task1.model.Result;
import com.c202201020417.task1.service.BooksService;
import com.c202201020417.task1.service.BorrowService;
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 org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class BorrowController {
@@ -24,6 +26,16 @@ public class BorrowController {
borrowService.addBorrow(borrow);
return "redirect:/bookpage";
}
+ @ResponseBody
+ @RequestMapping("/addborrowcommmit1")
+ public Result addborrowcommmit1(Borrow borrow)
+ { int result = borrowService.addBorrow(borrow);
+ if (result>=1){
+ return Result.ok();
+ }else {
+ return Result.error();
+ }
+ }
@RequestMapping("/updateborrow")
public String updateborrow(Borrow borrow,Model model)
{
diff --git a/src/main/java/com/c202201020417/task1/controller/ReviewsController.java b/src/main/java/com/c202201020417/task1/controller/ReviewsController.java
index 874256e..6a901f2 100644
--- a/src/main/java/com/c202201020417/task1/controller/ReviewsController.java
+++ b/src/main/java/com/c202201020417/task1/controller/ReviewsController.java
@@ -2,6 +2,7 @@ package com.c202201020417.task1.controller;
import com.c202201020417.task1.dao.ReviewsMapper;
import com.c202201020417.task1.model.Books;
+import com.c202201020417.task1.model.Result;
import com.c202201020417.task1.model.Reviews;
import com.c202201020417.task1.service.BooksService;
import com.c202201020417.task1.service.ReviewsService;
@@ -9,6 +10,7 @@ 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 org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class ReviewsController {
@@ -16,7 +18,7 @@ public class ReviewsController {
private ReviewsService reviewsService;
@RequestMapping("/addreview")
public String addreviews(Reviews reviews){
- return "addreview.html";
+ return "addreview.html";
}
@RequestMapping("/addreviewcommit")
public String addreviewcommit(Reviews reviews){
diff --git a/src/main/java/com/c202201020417/task1/dao/Books202201020417Mapper.java b/src/main/java/com/c202201020417/task1/dao/Books202201020417Mapper.java
new file mode 100644
index 0000000..58b515c
--- /dev/null
+++ b/src/main/java/com/c202201020417/task1/dao/Books202201020417Mapper.java
@@ -0,0 +1,19 @@
+package com.c202201020417.task1.dao;
+
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.c202201020417.task1.model.Books202201020417;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ *
+ * Mapper 接口
+ *
+ *
+ * @author 张三
+ * @since 2024-10-13
+ */
+@Mapper
+public interface Books202201020417Mapper extends BaseMapper {
+
+}
diff --git a/src/main/java/com/c202201020417/task1/dao/BooksMapper.java b/src/main/java/com/c202201020417/task1/dao/BooksMapper.java
index a032ca2..901b96b 100644
--- a/src/main/java/com/c202201020417/task1/dao/BooksMapper.java
+++ b/src/main/java/com/c202201020417/task1/dao/BooksMapper.java
@@ -1,5 +1,6 @@
package com.c202201020417.task1.dao;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.c202201020417.task1.model.Books;
import com.c202201020417.task1.model.Reviews;
diff --git a/src/main/java/com/c202201020417/task1/dao/ReviewsMapper.java b/src/main/java/com/c202201020417/task1/dao/ReviewsMapper.java
index aad6861..b74044a 100644
--- a/src/main/java/com/c202201020417/task1/dao/ReviewsMapper.java
+++ b/src/main/java/com/c202201020417/task1/dao/ReviewsMapper.java
@@ -9,5 +9,5 @@ import java.util.List;
@Mapper
public interface ReviewsMapper {
public List findReviewsByBooksId(int booksid);
- public int addReviews(Reviews reviews);
+ public int addReviews(Reviews reviews);
}
diff --git a/src/main/java/com/c202201020417/task1/model/Books.java b/src/main/java/com/c202201020417/task1/model/Books.java
index 7b5ed26..bf1dc04 100644
--- a/src/main/java/com/c202201020417/task1/model/Books.java
+++ b/src/main/java/com/c202201020417/task1/model/Books.java
@@ -3,6 +3,7 @@ package com.c202201020417.task1.model;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
+import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
@@ -11,10 +12,9 @@ public class Books {
private int id;
private String title;
private String author;
- private String publisher;
private String isbn;
- @DateTimeFormat(pattern = "yyyy-MM-dd")
- private Date published_date;
+ private String publisher;
+ private String published_date;
private List reviewsList;
private List usersList;
}
diff --git a/src/main/java/com/c202201020417/task1/model/Books202201020417.java b/src/main/java/com/c202201020417/task1/model/Books202201020417.java
new file mode 100644
index 0000000..8447147
--- /dev/null
+++ b/src/main/java/com/c202201020417/task1/model/Books202201020417.java
@@ -0,0 +1,39 @@
+package com.c202201020417.task1.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.io.Serializable;
+import java.time.LocalDateTime;
+import java.util.List;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.springframework.format.annotation.DateTimeFormat;
+
+/**
+ *
+ *
+ *
+ *
+ * @author 张三
+ * @since 2024-10-13
+ */
+@Getter
+@Setter
+public class Books202201020417 implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @TableId(value = "id", type = IdType.AUTO)
+ private Integer id;
+
+ private String title;
+
+ private String author;
+
+ private String isbn;
+
+ private String publisher;
+ @DateTimeFormat(pattern = "yyyy-MM-dd")
+ private LocalDateTime publishedDate;
+}
diff --git a/src/main/java/com/c202201020417/task1/model/Result.java b/src/main/java/com/c202201020417/task1/model/Result.java
new file mode 100644
index 0000000..6409fb8
--- /dev/null
+++ b/src/main/java/com/c202201020417/task1/model/Result.java
@@ -0,0 +1,58 @@
+package com.c202201020417.task1.model;
+import java.util.HashMap;
+import java.util.Map;
+/**
+ * 返回数据封装类
+ */
+public class Result extends HashMap {
+ private static final long serialVersionUID = 1L;
+
+ public Result() {
+ put("code", 0);
+ put("msg", "success");
+ }
+
+ public static Result error() {
+ return error(500, "未知异常,请联系管理员");
+ }
+
+ public static Result error(String msg) {
+ return error(500, msg);
+ }
+
+ public static Result error(int code, String msg) {
+ Result r = new Result();
+ r.put("code", code);
+ r.put("msg", msg);
+ return r;
+ }
+
+ public static Result ok(String msg) {
+ Result r = new Result();
+ r.put("msg", msg);
+ return r;
+ }
+
+
+ public static Result ok(Object obj) {
+ Result r = new Result();
+ r.put("data", obj);
+ return r;
+ }
+
+ public static Result ok(Map map) {
+ Result r = new Result();
+ r.putAll(map);
+ return r;
+ }
+
+ public static Result ok() {
+ return new Result();
+ }
+
+ public Result put(String key, Object value) {
+ super.put(key, value);
+ return this;
+ }
+}
+
diff --git a/src/main/java/com/c202201020417/task1/service/BooksService.java b/src/main/java/com/c202201020417/task1/service/BooksService.java
index aa2bb29..c9fef03 100644
--- a/src/main/java/com/c202201020417/task1/service/BooksService.java
+++ b/src/main/java/com/c202201020417/task1/service/BooksService.java
@@ -1,6 +1,8 @@
package com.c202201020417.task1.service;
+import com.baomidou.mybatisplus.extension.service.IService;
import com.c202201020417.task1.model.Books;
+import com.c202201020417.task1.model.Reviews;
import java.util.List;
@@ -10,4 +12,6 @@ public interface BooksService {
public int addBook(Books book);
public int deleteBook(int id);
public int updateBook(Books book);
+
+ public int addReview(Reviews reviews);
}
diff --git a/src/main/java/com/c202201020417/task1/service/IBooks202201020417Service.java b/src/main/java/com/c202201020417/task1/service/IBooks202201020417Service.java
new file mode 100644
index 0000000..934f88c
--- /dev/null
+++ b/src/main/java/com/c202201020417/task1/service/IBooks202201020417Service.java
@@ -0,0 +1,19 @@
+package com.c202201020417.task1.service;
+
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.c202201020417.task1.model.Books202201020417;
+import com.c202201020417.task1.model.Reviews;
+
+/**
+ *
+ * 服务类
+ *
+ *
+ * @author 张三
+ * @since 2024-10-13
+ */
+public interface IBooks202201020417Service extends IService {
+
+ int addReview(Reviews review);
+}
diff --git a/src/main/java/com/c202201020417/task1/service/impl/Books202201020417ServiceImpl.java b/src/main/java/com/c202201020417/task1/service/impl/Books202201020417ServiceImpl.java
new file mode 100644
index 0000000..7b6f79c
--- /dev/null
+++ b/src/main/java/com/c202201020417/task1/service/impl/Books202201020417ServiceImpl.java
@@ -0,0 +1,30 @@
+package com.c202201020417.task1.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.c202201020417.task1.dao.Books202201020417Mapper;
+import com.c202201020417.task1.dao.ReviewsMapper;
+import com.c202201020417.task1.model.Books202201020417;
+import com.c202201020417.task1.model.Reviews;
+import com.c202201020417.task1.service.IBooks202201020417Service;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ *
+ * 服务实现类
+ *
+ *
+ * @author 张三
+ * @since 2024-10-13
+ */
+@Service
+public class Books202201020417ServiceImpl extends ServiceImpl implements IBooks202201020417Service {
+
+ @Autowired
+ private ReviewsMapper reviewsMapper;
+
+ @Override
+ public int addReview(Reviews review) {
+ return reviewsMapper.addReviews(review);
+ }
+}
diff --git a/src/main/java/com/c202201020417/task1/service/impl/BooksServiceImpl.java b/src/main/java/com/c202201020417/task1/service/impl/BooksServiceImpl.java
index d5f37bd..27585be 100644
--- a/src/main/java/com/c202201020417/task1/service/impl/BooksServiceImpl.java
+++ b/src/main/java/com/c202201020417/task1/service/impl/BooksServiceImpl.java
@@ -1,6 +1,7 @@
package com.c202201020417.task1.service.impl;
import com.c202201020417.task1.dao.BooksMapper;
+import com.c202201020417.task1.dao.ReviewsMapper;
import com.c202201020417.task1.model.Books;
import com.c202201020417.task1.model.Reviews;
import com.c202201020417.task1.service.BooksService;
@@ -13,6 +14,8 @@ import java.util.List;
public class BooksServiceImpl implements BooksService {
@Autowired
private BooksMapper booksMapper;
+ @Autowired
+ private ReviewsMapper reviewsMapper;
@Override
public List getAllBook() {
return booksMapper.getAllBook();
@@ -33,7 +36,7 @@ public class BooksServiceImpl implements BooksService {
return booksMapper.updateBook(book);
}
-
-
+ @Override
+ public int addReview(Reviews reviews) {return reviewsMapper.addReviews(reviews);}
}
diff --git a/src/main/java/com/c202201020417/task1/service/impl/ReviewsServiceImpl.java b/src/main/java/com/c202201020417/task1/service/impl/ReviewsServiceImpl.java
index ee99dc5..9bae922 100644
--- a/src/main/java/com/c202201020417/task1/service/impl/ReviewsServiceImpl.java
+++ b/src/main/java/com/c202201020417/task1/service/impl/ReviewsServiceImpl.java
@@ -17,10 +17,10 @@ public class ReviewsServiceImpl implements ReviewsService {
return List.of();
}
+
@Override
- public int addReviews(Reviews reviews)
- {
- return reviewsMapper.addReviews(reviews);
+ public int addReviews(Reviews reviews) {
+ return reviewsMapper.addReviews(reviews); // 通过 reviewsMapper 实例调用方法
}
}
diff --git a/src/main/resources/mapper/Books202201020417Mapper.xml b/src/main/resources/mapper/Books202201020417Mapper.xml
new file mode 100644
index 0000000..54cb855
--- /dev/null
+++ b/src/main/resources/mapper/Books202201020417Mapper.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/src/main/resources/mapper/BooksMapper.xml b/src/main/resources/mapper/BooksMapper.xml
index 6523ba9..3ceb9d1 100644
--- a/src/main/resources/mapper/BooksMapper.xml
+++ b/src/main/resources/mapper/BooksMapper.xml
@@ -7,6 +7,7 @@
insert into books202201020417(title,author,isbn,publisher,published_date) values(#{title},#{author},#{isbn},#{publisher},#{published_date})
+
delete from books202201020417 where id=#{id}