第三次作业提交
This commit is contained in:
parent
5e14812a36
commit
608a60218d
|
@ -61,17 +61,39 @@
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<!-- <dependency>-->
|
||||||
<groupId>org.mybatis.spring.boot</groupId>
|
<!-- <groupId>org.mybatis.spring.boot</groupId>-->
|
||||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
<!-- <artifactId>mybatis-spring-boot-starter</artifactId>-->
|
||||||
<version>3.0.3</version>
|
<!-- <version>3.0.3</version>-->
|
||||||
</dependency>
|
<!-- </dependency>-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
<version>8.0.25</version>
|
<version>8.0.25</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||||
|
<version>3.5.7</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<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>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -5,7 +5,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class Task1Application {
|
public class Task1Application {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(Task1Application.class, args);
|
SpringApplication.run(Task1Application.class, args);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,28 +3,33 @@ package com.c202101080138.task1.controller;
|
||||||
import com.c202101080138.task1.model.Book;
|
import com.c202101080138.task1.model.Book;
|
||||||
import com.c202101080138.task1.model.Review;
|
import com.c202101080138.task1.model.Review;
|
||||||
import com.c202101080138.task1.service.BookService;
|
import com.c202101080138.task1.service.BookService;
|
||||||
|
import com.c202101080138.task1.utils.Result;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
|
|
||||||
|
@CrossOrigin
|
||||||
@Controller
|
@RestController
|
||||||
public class BookController {
|
public class BookController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private BookService bookService;
|
private BookService bookService;
|
||||||
|
|
||||||
@RequestMapping("booklist")
|
@RequestMapping("booklist")
|
||||||
public String bookList(Model model, String title){
|
public Result booklist(){
|
||||||
// model.addAttribute("books",bookService.getBooks());
|
return Result.ok(bookService.getBooks());
|
||||||
|
}
|
||||||
|
// @RequestMapping("booklist")
|
||||||
|
// public String bookList(Model model, String title){
|
||||||
|
//// model.addAttribute("books",bookService.getBooks());
|
||||||
|
//// return "booklist.html";
|
||||||
|
// if(title!=null&&!title.equals("")){
|
||||||
|
// model.addAttribute("books", bookService.searchBooksByName(title));
|
||||||
|
// }else{
|
||||||
|
// model.addAttribute("books", bookService.getBooks());
|
||||||
|
// }
|
||||||
// return "booklist.html";
|
// return "booklist.html";
|
||||||
if(title!=null&&!title.equals("")){
|
// }
|
||||||
model.addAttribute("books", bookService.searchBooksByName(title));
|
|
||||||
}else{
|
|
||||||
model.addAttribute("books", bookService.getBooks());
|
|
||||||
}
|
|
||||||
return "booklist.html";
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping("addbook")
|
@RequestMapping("addbook")
|
||||||
public String addbook(Book book){
|
public String addbook(Book book){
|
||||||
|
@ -32,11 +37,15 @@ public class BookController {
|
||||||
return "redirect:booklist";
|
return "redirect:booklist";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("deleteBookCommit")
|
// @RequestMapping("deleteBookCommit")
|
||||||
public String deleteBook(int id){
|
// public String deleteBook(int id){
|
||||||
bookService.deleteBook(id);
|
// bookService.deleteBook(id);
|
||||||
return "bookmanage.html";
|
// return "bookmanage.html";
|
||||||
}
|
// }
|
||||||
|
@RequestMapping("/deleteBook/{id}")
|
||||||
|
public Result deleteBook(@PathVariable int id){
|
||||||
|
return Result.ok(bookService.deleteBook(id));
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping("addbookpage")
|
@RequestMapping("addbookpage")
|
||||||
public String addBookPage(){
|
public String addBookPage(){
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.c202101080138.task1.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.c202101080138.task1.model.Book;
|
||||||
|
import com.c202101080138.task1.service.IStudentService;
|
||||||
|
import com.c202101080138.task1.utils.Result;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@CrossOrigin
|
||||||
|
@RestController
|
||||||
|
public class JsonController {
|
||||||
|
|
||||||
|
// @Autowired
|
||||||
|
// IStudentService studentService;
|
||||||
|
// @RequestMapping("login1")
|
||||||
|
// public Result login1(String username, String password){
|
||||||
|
// if ("admin".equals(username) && "123".equals(password)){
|
||||||
|
// return Result.ok("登录成功");
|
||||||
|
// }
|
||||||
|
// return Result.error("登录失败");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// @RequestMapping("getbooks")
|
||||||
|
// public Result getBooks(){
|
||||||
|
//// if(search!=null && !search.equals("")){
|
||||||
|
//// QueryWrapper<Book> queryWrapper = new QueryWrapper<>();
|
||||||
|
//// queryWrapper.like("title",search).or().like("author",search);
|
||||||
|
//// return Result.ok(iStudentService.getBaseMapper().selectList(queryWrapper));
|
||||||
|
//// }
|
||||||
|
// return Result.ok(studentService.list());
|
||||||
|
// }
|
||||||
|
}
|
|
@ -1,11 +1,15 @@
|
||||||
package com.c202101080138.task1.controller;
|
package com.c202101080138.task1.controller;
|
||||||
|
|
||||||
import com.c202101080138.task1.dao.UserMapper;
|
import com.c202101080138.task1.dao.UserMapper;
|
||||||
|
import com.c202101080138.task1.service.BookService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import com.c202101080138.task1.utils.Result;
|
||||||
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@Controller
|
@RestController
|
||||||
|
@CrossOrigin
|
||||||
public class LoginController {
|
public class LoginController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserMapper userMapper;
|
private UserMapper userMapper;
|
||||||
|
@ -14,11 +18,19 @@ public class LoginController {
|
||||||
return "login.html";
|
return "login.html";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @RequestMapping("loginCommit")
|
||||||
|
// public String loginCommit(String username, String password) {
|
||||||
|
// if (password.equals(userMapper.getPassword(username))) {
|
||||||
|
// return "bookmanage.html";
|
||||||
|
// }
|
||||||
|
// else return "loginfail.html";
|
||||||
|
// }
|
||||||
@RequestMapping("loginCommit")
|
@RequestMapping("loginCommit")
|
||||||
public String loginCommit(String username, String password) {
|
public Result loginCommit(String username, String password){
|
||||||
if (password.equals(userMapper.getPassword(username))) {
|
if (password.equals(userMapper.getPassword(username))) {
|
||||||
return "bookmanage.html";
|
return Result.ok("登录成功");
|
||||||
}
|
}
|
||||||
else return "loginfail.html";
|
else
|
||||||
|
return Result.error("密码错误");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ public class RegisterController {
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private User user;
|
private User user;
|
||||||
|
|
||||||
@RequestMapping("register")
|
@RequestMapping("register")
|
||||||
public String signup(String username,String password){
|
public String signup(String username,String password){
|
||||||
return "register.html";
|
return "register.html";
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.c202101080138.task1.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.c202101080138.task1.model.Book;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author 张三
|
||||||
|
* @since 2024-09-12
|
||||||
|
*/
|
||||||
|
public interface IStudentService extends IService<Book> {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
package com.c202101080138.task1.utils;
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,8 +12,9 @@ spring.datasource.username=202101080138
|
||||||
spring.datasource.password=@hnucm1254
|
spring.datasource.password=@hnucm1254
|
||||||
#??????????MyBatis??
|
#??????????MyBatis??
|
||||||
#??Mybatis?Mapper??
|
#??Mybatis?Mapper??
|
||||||
mybatis.mapper-locations=classpath:mapper/*.xml
|
mybatis-plus.mapper-locations=classpath:mapper/*.xml
|
||||||
#??Mybatis?????
|
#??Mybatis?????
|
||||||
mybatis.type-aliases-package=com.c202101080138.task1.model
|
mybatis-plus.type-aliases-package=com.c202101080138.task1.model
|
||||||
|
|
||||||
logging.level.com.example.springmybatis = debug
|
#logging.level.com.example.springmybatis = debug
|
||||||
|
logging.level.com.spring.springboot = debug
|
Loading…
Reference in New Issue