24.11.05第四次作业,有些修改
This commit is contained in:
parent
d76c7797be
commit
78aa53ebec
25
pom.xml
25
pom.xml
|
@ -60,17 +60,28 @@
|
|||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.mybatis.spring.boot</groupId>-->
|
||||
<!-- <artifactId>mybatis-spring-boot-starter</artifactId>-->
|
||||
<!-- <version>3.0.3</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<version>3.5.14</version>
|
||||
<scope>compile</scope>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
<version>3.5.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>3.0.3</version>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<version>3.5.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
<version>2.3.31</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -2,16 +2,20 @@ package com.c202201020121.task1.homework.controller;
|
|||
|
||||
import com.c202201020121.task1.homework.model.Books;
|
||||
import com.c202201020121.task1.homework.model.Evaluations;
|
||||
import com.c202201020121.task1.homework.model.Result;
|
||||
import com.c202201020121.task1.homework.service.BooksService;
|
||||
import com.c202201020121.task1.homework.service.EvaluationsService;
|
||||
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.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CrossOrigin
|
||||
@Controller
|
||||
public class BooksController {
|
||||
|
||||
|
@ -21,60 +25,79 @@ public class BooksController {
|
|||
@Autowired
|
||||
private EvaluationsService evaluationsService;
|
||||
|
||||
// @RequestMapping("/getbooks")
|
||||
// public String getBooks(String username, String password,Model model) {
|
||||
//// if (username.equals("admin")&&password.equals("123456")){
|
||||
// model.addAttribute("booksList", booksService.getBooks());
|
||||
// return "main.html";
|
||||
//// }
|
||||
//// return "login.html";
|
||||
// }
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/getbooks")
|
||||
public String getBooks(Model model) {
|
||||
model.addAttribute("booksList", booksService.getBooks());
|
||||
// model.addAttribute("evaluationsList", evaluationsService.getEvaluations());
|
||||
return "main.html";
|
||||
public Result getBooks() {
|
||||
List<Books> booksList = booksService.getBooks();
|
||||
if (booksList!= null &&!booksList.isEmpty()) {
|
||||
// 如果获取到书籍列表成功,返回包含数据的Result,状态码为默认的0(成功),消息为"success"
|
||||
return Result.ok().put("data", booksList);
|
||||
} else {
|
||||
// 如果获取书籍列表失败,返回错误信息的Result,这里假设状态码为500表示获取数据失败,消息可自定义
|
||||
return Result.error(500, "获取书籍列表失败");
|
||||
}
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/addbookspage")
|
||||
public String addBooks() {
|
||||
return "addbookspage.html";
|
||||
public Result addBooksPage() {
|
||||
return Result.ok().put("page", "addbookspage.html");
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/addbookscommit")
|
||||
public String addBooksCommit(Books books) {
|
||||
booksService.addBooks(books);
|
||||
return "redirect:/getbooks";
|
||||
public Result addBooksCommit(Books books) {
|
||||
try {
|
||||
booksService.addBooks(books);
|
||||
return Result.ok();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/deletebooks")
|
||||
public String deleteBooks(int id) {
|
||||
booksService.deleteBooks(id);
|
||||
return "redirect:/getbooks";
|
||||
public Result deleteBooks(int id) {
|
||||
try {
|
||||
booksService.deleteBooks(id);
|
||||
return Result.ok();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/updatebookspage")
|
||||
public String updateBooks(Books books,Model model) {
|
||||
model.addAttribute("books",books);
|
||||
return "updatebooks.html";
|
||||
public Result updateBooksPage(Books books, Model model) {
|
||||
model.addAttribute("books", books);
|
||||
return Result.ok().put("page", "updatebooks.html");
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/updatebookscommit")
|
||||
public String updateBooksCommit(Books books) {
|
||||
booksService.updateBooks(books);
|
||||
return "redirect:/getbooks";
|
||||
public Result updateBooksCommit(Books books) {
|
||||
try {
|
||||
booksService.updateBooks(books);
|
||||
return Result.ok();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/addbooksevaluations")
|
||||
public String addBooksEvaluations() {
|
||||
return "addbooksevaluations.html";
|
||||
public Result addBooksEvaluations() {
|
||||
return Result.ok().put("page", "addbooksevaluations.html");
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/addbooksevaluationscommit")
|
||||
public String addBooksEvaluationsCommit(Evaluations evaluations) {
|
||||
evaluationsService.addEvaluations(evaluations);
|
||||
return "redirect:/getbooks";
|
||||
public Result addBooksEvaluationsCommit(Evaluations evaluations) {
|
||||
try {
|
||||
evaluationsService.addEvaluations(evaluations);
|
||||
return Result.ok();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,63 +3,118 @@ package com.c202201020121.task1.homework.controller;
|
|||
//import ch.qos.logback.core.model.Model;
|
||||
//import com.c202201020121.task1.homework.model.Borrow_records;
|
||||
import com.c202201020121.task1.homework.model.Borrow_records;
|
||||
import com.c202201020121.task1.homework.model.Result;
|
||||
import com.c202201020121.task1.homework.service.Borrow_recordsService;
|
||||
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;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@CrossOrigin
|
||||
@Controller
|
||||
public class Borrow_recordsController {
|
||||
@Autowired
|
||||
public Borrow_recordsService borrow_recordsService;
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/getborrow_records")
|
||||
public String getBorrow_records(Model model)
|
||||
{
|
||||
model.addAttribute("borrow_recordsList",borrow_recordsService.getBorrow_records());
|
||||
return "borrow_records.html";
|
||||
public Result getBorrow_records() {
|
||||
List<Borrow_records> borrowRecordsList = borrow_recordsService.getBorrow_records();
|
||||
return Result.ok().put("data", borrowRecordsList);
|
||||
}
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/addborrow_recordspage")
|
||||
public String addBorrow_recordsPage()
|
||||
{
|
||||
return "addborrow_records.html";
|
||||
public Result addBorrow_recordsPage() {
|
||||
return Result.ok().put("page", "addborrow_records.html");
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/addborrow_recordscommit")
|
||||
public String addBorrow_recordsCommit(Borrow_records borrow_records)
|
||||
{
|
||||
borrow_recordsService.addBorrow_records(borrow_records);
|
||||
return "redirect:/getborrow_records";
|
||||
public Result addBorrow_recordsCommit(Borrow_records borrow_records) {
|
||||
try {
|
||||
borrow_recordsService.addBorrow_records(borrow_records);
|
||||
return Result.ok();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/deleteborrow_records")
|
||||
public String deleteBorrow_records(int id)
|
||||
{
|
||||
borrow_recordsService.deleteBorrow_records(id);
|
||||
return "redirect:/getborrow_records";
|
||||
public Result deleteBorrow_records(int id) {
|
||||
try {
|
||||
borrow_recordsService.deleteBorrow_records(id);
|
||||
return Result.ok();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/updateborrow_recordspage")
|
||||
public String updateBorrow_records(Borrow_records borrow_records,Model model)
|
||||
{
|
||||
model.addAttribute("borrow_records",borrow_records);
|
||||
return "updateborrow_records.html";
|
||||
public Result updateBorrow_recordsPage(Borrow_records borrow_records, Model model) {
|
||||
model.addAttribute("borrow_records", borrow_records);
|
||||
return Result.ok().put("page", "updateborrow_records.html");
|
||||
}
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/updateborrow_recordscommit")
|
||||
public String updateBorrow_recordsCommit(Borrow_records borrow_records)
|
||||
{
|
||||
borrow_recordsService.updateBorrow_records(borrow_records);
|
||||
return "redirect:/getborrow_records";
|
||||
public Result updateBorrow_recordsCommit(Borrow_records borrow_records) {
|
||||
try {
|
||||
borrow_recordsService.updateBorrow_records(borrow_records);
|
||||
return Result.ok();
|
||||
} catch (Exception e) {
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
//
|
||||
// @RequestMapping("/getborrow_records")
|
||||
// public String getBorrow_records(Model model)
|
||||
// {
|
||||
// model.addAttribute("borrow_recordsList",borrow_recordsService.getBorrow_records());
|
||||
// return "borrow_records.html";
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @RequestMapping("/addborrow_recordspage")
|
||||
// public String addBorrow_recordsPage()
|
||||
// {
|
||||
// return "addborrow_records.html";
|
||||
// }
|
||||
//
|
||||
// @RequestMapping("/addborrow_recordscommit")
|
||||
// public String addBorrow_recordsCommit(Borrow_records borrow_records)
|
||||
// {
|
||||
// borrow_recordsService.addBorrow_records(borrow_records);
|
||||
// return "redirect:/getborrow_records";
|
||||
// }
|
||||
//
|
||||
// @RequestMapping("/deleteborrow_records")
|
||||
// public String deleteBorrow_records(int id)
|
||||
// {
|
||||
// borrow_recordsService.deleteBorrow_records(id);
|
||||
// return "redirect:/getborrow_records";
|
||||
// }
|
||||
//
|
||||
// @RequestMapping("/updateborrow_recordspage")
|
||||
// public String updateBorrow_records(Borrow_records borrow_records,Model model)
|
||||
// {
|
||||
// model.addAttribute("borrow_records",borrow_records);
|
||||
// return "updateborrow_records.html";
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @RequestMapping("/updateborrow_recordscommit")
|
||||
// public String updateBorrow_recordsCommit(Borrow_records borrow_records)
|
||||
// {
|
||||
// borrow_recordsService.updateBorrow_records(borrow_records);
|
||||
// return "redirect:/getborrow_records";
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package com.c202201020121.task1.homework.controller;
|
||||
|
||||
import com.c202201020121.task1.homework.model.Result;
|
||||
import com.c202201020121.task1.homework.model.Reviews202201020121;
|
||||
import com.c202201020121.task1.homework.service.IReviews202201020121Service;
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author 作者是橘子大王
|
||||
* @since 2024-11-03
|
||||
*/
|
||||
@CrossOrigin
|
||||
@Controller
|
||||
@RequestMapping("/reviews202201020121")
|
||||
public class Reviews202201020121Controller {
|
||||
|
||||
@Autowired
|
||||
IReviews202201020121Service iReviews202201020121Service;
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("reviewslist")
|
||||
public Result getReviewsList(){
|
||||
List<Reviews202201020121> list = iReviews202201020121Service.list();
|
||||
return Result.ok().put("data",list);
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("addReviews")
|
||||
public Result addReviews(Reviews202201020121 reviews){
|
||||
Boolean result = iReviews202201020121Service.save(reviews);
|
||||
if (result){
|
||||
return Result.ok();
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("updateReviews")
|
||||
public Result updateReviews(Reviews202201020121 reviews){
|
||||
Boolean result = iReviews202201020121Service.updateById(reviews);
|
||||
if (result){
|
||||
return Result.ok();
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("deleteReviews")
|
||||
public Result deleteReviews(int id){
|
||||
Boolean result = iReviews202201020121Service.removeById(id);
|
||||
if (result){
|
||||
return Result.ok();
|
||||
}
|
||||
return Result.error();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.c202201020121.task1.homework.dao;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.c202201020121.task1.homework.model.Reviews202201020121;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 作者是橘子大王
|
||||
* @since 2024-11-03
|
||||
*/
|
||||
@Mapper
|
||||
public interface Reviews202201020121Mapper extends BaseMapper<Reviews202201020121> {
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.c202201020121.task1.homework.model;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 返回数据封装类
|
||||
*/
|
||||
public class Result extends HashMap<String, Object> {
|
||||
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<String, Object> 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package com.c202201020121.task1.homework.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author 作者是橘子大王
|
||||
* @since 2024-11-03
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class Reviews202201020121 implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
private String evaluation;
|
||||
|
||||
private Integer userid;
|
||||
|
||||
private Integer bookid;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.c202201020121.task1.homework.service;
|
||||
|
||||
//import com.baomidou.mybatisplus.model.Reviews202201020121;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.c202201020121.task1.homework.model.Reviews202201020121;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 作者是橘子大王
|
||||
* @since 2024-11-03
|
||||
*/
|
||||
public interface IReviews202201020121Service extends IService<Reviews202201020121> {
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.c202201020121.task1.homework.service.impl;
|
||||
|
||||
//import com.baomidou.mybatisplus.model.Reviews202201020121;
|
||||
//import com.baomidou.mybatisplus.mapper.Reviews202201020121Mapper;
|
||||
//import com.baomidou.mybatisplus.service.IReviews202201020121Service;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.c202201020121.task1.homework.dao.Reviews202201020121Mapper;
|
||||
import com.c202201020121.task1.homework.model.Reviews202201020121;
|
||||
import com.c202201020121.task1.homework.service.IReviews202201020121Service;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author 作者是橘子大王
|
||||
* @since 2024-11-03
|
||||
*/
|
||||
@Service
|
||||
public class Reviews202201020121ServiceImpl extends ServiceImpl<Reviews202201020121Mapper, Reviews202201020121> implements IReviews202201020121Service {
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.c202201020121.task1.homework;
|
||||
|
||||
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://10.33.66.120:3306/task202201020121?serverTimezone=UTC",
|
||||
"202201020121",
|
||||
"@hnucm1254")
|
||||
.globalConfig(builder -> builder
|
||||
.author("作者是橘子大王")
|
||||
.outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java")
|
||||
.commentDate("yyyy-MM-dd")
|
||||
)
|
||||
.packageConfig(builder -> builder
|
||||
.parent("com.baomidou.mybatisplus")
|
||||
.entity("model")
|
||||
.mapper("mapper")
|
||||
.service("service")
|
||||
.serviceImpl("service.impl")
|
||||
.xml("mapper.xml")
|
||||
)
|
||||
.strategyConfig(builder -> builder
|
||||
.entityBuilder()
|
||||
.enableLombok()
|
||||
)
|
||||
.templateEngine(new FreemarkerTemplateEngine())
|
||||
.execute();
|
||||
}
|
||||
}
|
|
@ -11,8 +11,8 @@ spring.datasource.username=202201020121
|
|||
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.c202201020121.task1.homework.model
|
||||
mybatis-plus.type-aliases-package=com.c202201020121.task1.homework.model
|
||||
#????
|
||||
logging.level.com.liulingzhi.springboot.springboot = debug
|
|
@ -0,0 +1,5 @@
|
|||
<?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.c202201020121.task1.homework.dao.Reviews202201020121Mapper">
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue