diff --git a/pom.xml b/pom.xml
index 3fe5743..2edc014 100644
--- a/pom.xml
+++ b/pom.xml
@@ -60,16 +60,33 @@
spring-boot-starter-test
test
+
- org.mybatis.spring.boot
- mybatis-spring-boot-starter
- 3.0.3
+ com.baomidou
+ mybatis-plus-generator
+ 3.5.7
+
+
+ org.freemarker
+ freemarker
+ 2.3.31
+
+
mysql
mysql-connector-java
8.0.25
- compile
+
+
+ mavenrepository.org.mapstruct
+ mapstruct
+ 1.3.1.Final
+
+
+ com.baomidou
+ mybatis-plus-spring-boot3-starter
+ 3.5.7
diff --git a/src/main/java/com/c202201020140/tasks/Test.java b/src/main/java/com/c202201020140/tasks/Test.java
new file mode 100644
index 0000000..74cba46
--- /dev/null
+++ b/src/main/java/com/c202201020140/tasks/Test.java
@@ -0,0 +1,34 @@
+package com.c202201020140.tasks;
+
+import com.baomidou.mybatisplus.generator.FastAutoGenerator;
+import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
+
+import java.nio.file.Paths;
+
+public class Test {
+ public static void main(String[] args) {
+ FastAutoGenerator.create("jdbc:mysql://106.53.194.250:63306/***?serverTimezone=UTC",
+ "**", "@hnucm1254")
+ .globalConfig(builder -> builder
+ .author("Baomidou")
+ .outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java")
+ .commentDate("yyyy-MM-dd")
+ )
+ .packageConfig(builder -> builder
+ .parent("com.baomidou.mybatisplus")
+ .entity("entity")
+ .mapper("mapper")
+ .service("service")
+ .serviceImpl("service.impl")
+ .xml("mapper.xml")
+ )
+ .strategyConfig(builder -> builder
+ .entityBuilder()
+ .enableLombok()
+ )
+ .templateEngine(new FreemarkerTemplateEngine())
+ .execute();
+ }
+ }
+
+
diff --git a/src/main/java/com/c202201020140/tasks/controller/BookController.java b/src/main/java/com/c202201020140/tasks/controller/BookController.java
index 5e05d28..eea7a89 100644
--- a/src/main/java/com/c202201020140/tasks/controller/BookController.java
+++ b/src/main/java/com/c202201020140/tasks/controller/BookController.java
@@ -30,7 +30,7 @@ public class BookController {
}
@RequestMapping("/deletebook")
public String delBook(int id){
- bookService.deleteBook(id);
+ bookService.deleteBook(id);
return "redirect:/book";
}
@RequestMapping("/updatebook")
@@ -40,7 +40,7 @@ public class BookController {
}
@RequestMapping("/updatebookcommit")
public String updatebookcommit(Book book){
- bookService.updateBook(book);
+ bookService.updateBook(book);
return "redirect:/book";
}
@RequestMapping("/addreview")
diff --git a/src/main/java/com/c202201020140/tasks/controller/BookListController.java b/src/main/java/com/c202201020140/tasks/controller/BookListController.java
new file mode 100644
index 0000000..e2fd556
--- /dev/null
+++ b/src/main/java/com/c202201020140/tasks/controller/BookListController.java
@@ -0,0 +1,80 @@
+package com.c202201020140.tasks.controller;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.c202201020140.tasks.model.Result;
+import com.c202201020140.tasks.model.BookList;
+import com.c202201020140.tasks.service.IBookListService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import java.util.List;
+
+@CrossOrigin
+@Controller //控制器负责处理来自客户端的 HTTP 请求,并返回相应的响应。
+@RequestMapping("/bookList")
+public class BookListController {
+
+ //JSON方法返回数据
+ @Autowired//它可以用于字段、构造器、setter 方法等地方,Spring 容器会自动将匹配的 Bean 注入
+ IBookListService bookListService;
+ @ResponseBody //返回 JSON、XML 等格式的数据。
+ @RequestMapping("/BookList1")
+ public Result getBookList1(){
+ QueryWrapper queryWrapper=new QueryWrapper<>();
+ queryWrapper.like("name", "test").or().eq("age",19);
+ List list = bookListService.list(queryWrapper);
+ return Result.ok().put("data",list);
+
+ }
+ @ResponseBody //返回 JSON、XML 等格式的数据。
+ @RequestMapping("/login")
+ public Result login(String username,String password){
+ //todo=>查询数据库
+ if(username.equals("admin")&&password.equals("123456")){
+ return Result.ok("登录成功");
+ }
+ return Result.error("用户名或密码错误");
+ }
+
+
+ @ResponseBody //返回 JSON、XML 等格式的数据。
+ @RequestMapping("/BookList11")
+ public Result getStudentList(){
+ List list = bookListService.list();
+ return Result.ok().put("data",list);
+ }
+
+ @ResponseBody
+ @RequestMapping("/addBookList")
+ public Result addBookList(BookList bookList){
+ boolean result = bookListService.save(bookList);
+ if(!result){
+ return Result.error("添加失败");
+ }
+ return Result.ok();
+ }
+
+ @ResponseBody
+ @RequestMapping("/updateBookList")
+ public Result updateBookList(BookList bookList){
+ boolean result = bookListService.saveOrUpdate(bookList);
+ if(!result){
+ return Result.error("修改失败");
+ }
+ return Result.ok();
+ }
+
+ @ResponseBody
+ @RequestMapping("/deleteBookList")
+ public Result deleteBookList(Integer id){
+ boolean result = bookListService.removeById(id);
+ if(!result){
+ return Result.error("删除失败");
+ }
+ return Result.ok();
+ }
+
+}
diff --git a/src/main/java/com/c202201020140/tasks/dao/BookListMapper.java b/src/main/java/com/c202201020140/tasks/dao/BookListMapper.java
new file mode 100644
index 0000000..19e0eab
--- /dev/null
+++ b/src/main/java/com/c202201020140/tasks/dao/BookListMapper.java
@@ -0,0 +1,12 @@
+package com.c202201020140.tasks.dao;
+
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.c202201020140.tasks.model.BookList;
+import org.apache.ibatis.annotations.Mapper;
+
+
+@Mapper
+public interface BookListMapper extends BaseMapper {
+
+}
diff --git a/src/main/java/com/c202201020140/tasks/model/BookList.java b/src/main/java/com/c202201020140/tasks/model/BookList.java
new file mode 100644
index 0000000..bc03b79
--- /dev/null
+++ b/src/main/java/com/c202201020140/tasks/model/BookList.java
@@ -0,0 +1,26 @@
+package com.c202201020140.tasks.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serializable;
+
+@Getter
+@Setter
+public class BookList 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;
+ private String published_date;
+
+
+}
diff --git a/src/main/java/com/c202201020140/tasks/model/Result.java b/src/main/java/com/c202201020140/tasks/model/Result.java
new file mode 100644
index 0000000..13695ae
--- /dev/null
+++ b/src/main/java/com/c202201020140/tasks/model/Result.java
@@ -0,0 +1,63 @@
+package com.c202201020140.tasks.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/c202201020140/tasks/service/IBookListService.java b/src/main/java/com/c202201020140/tasks/service/IBookListService.java
new file mode 100644
index 0000000..4a35953
--- /dev/null
+++ b/src/main/java/com/c202201020140/tasks/service/IBookListService.java
@@ -0,0 +1,11 @@
+package com.c202201020140.tasks.service;
+
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.c202201020140.tasks.model.BookList;
+
+
+
+public interface IBookListService extends IService {
+
+}
diff --git a/src/main/java/com/c202201020140/tasks/service/impl/BookListServiceImpl.java b/src/main/java/com/c202201020140/tasks/service/impl/BookListServiceImpl.java
new file mode 100644
index 0000000..c2fb8f4
--- /dev/null
+++ b/src/main/java/com/c202201020140/tasks/service/impl/BookListServiceImpl.java
@@ -0,0 +1,14 @@
+package com.c202201020140.tasks.service.impl;
+
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.c202201020140.tasks.dao.BookListMapper;
+import com.c202201020140.tasks.model.BookList;
+import com.c202201020140.tasks.service.IBookListService;
+import org.springframework.stereotype.Service;
+
+
+@Service
+public class BookListServiceImpl extends ServiceImpl implements IBookListService {
+
+}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 406e2cc..57993cc 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -9,8 +9,8 @@ spring.datasource.username=202201020140
spring.datasource.password=@hnucm1254
#??????????MyBatis??
#??Mybatis?Mapper??
-mybatis.mapper-locations=classpath:mapper/*.xml
+mybatis-plus.mapper-locations=classpath:mapper/*.xml
#??Mybatis?????
-mybatis.type-aliases-package=com.c202201020140.tasks.model
+mybatis-plus.type-aliases-package=com.c202201020140.tasks.model
#????
logging.level.com.yilinxuan.springboot.springboot = debug
diff --git a/src/main/resources/mapper/BookListMapper.xml b/src/main/resources/mapper/BookListMapper.xml
new file mode 100644
index 0000000..3a4f6a0
--- /dev/null
+++ b/src/main/resources/mapper/BookListMapper.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file