第三次作业提交
This commit is contained in:
parent
5e14812a36
commit
608a60218d
|
@ -61,17 +61,39 @@
|
|||
<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.spring.boot</groupId>-->
|
||||
<!-- <artifactId>mybatis-spring-boot-starter</artifactId>-->
|
||||
<!-- <version>3.0.3</version>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.25</version>
|
||||
</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>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -5,7 +5,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
|
||||
@SpringBootApplication
|
||||
public class Task1Application {
|
||||
|
||||
public static void main(String[] 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.Review;
|
||||
import com.c202101080138.task1.service.BookService;
|
||||
import com.c202101080138.task1.utils.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.ui.Model;
|
||||
|
||||
|
||||
@Controller
|
||||
@CrossOrigin
|
||||
@RestController
|
||||
public class BookController {
|
||||
@Autowired
|
||||
private BookService bookService;
|
||||
|
||||
@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";
|
||||
public Result booklist(){
|
||||
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";
|
||||
// }
|
||||
|
||||
@RequestMapping("addbook")
|
||||
public String addbook(Book book){
|
||||
|
@ -32,11 +37,15 @@ public class BookController {
|
|||
return "redirect:booklist";
|
||||
}
|
||||
|
||||
@RequestMapping("deleteBookCommit")
|
||||
public String deleteBook(int id){
|
||||
bookService.deleteBook(id);
|
||||
return "bookmanage.html";
|
||||
}
|
||||
// @RequestMapping("deleteBookCommit")
|
||||
// public String deleteBook(int id){
|
||||
// bookService.deleteBook(id);
|
||||
// return "bookmanage.html";
|
||||
// }
|
||||
@RequestMapping("/deleteBook/{id}")
|
||||
public Result deleteBook(@PathVariable int id){
|
||||
return Result.ok(bookService.deleteBook(id));
|
||||
}
|
||||
|
||||
@RequestMapping("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;
|
||||
|
||||
import com.c202101080138.task1.dao.UserMapper;
|
||||
import com.c202101080138.task1.service.BookService;
|
||||
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.RestController;
|
||||
|
||||
@Controller
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
public class LoginController {
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
@ -14,11 +18,19 @@ public class LoginController {
|
|||
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")
|
||||
public String loginCommit(String username, String password) {
|
||||
public Result loginCommit(String username, String password){
|
||||
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;
|
||||
@Autowired
|
||||
private User user;
|
||||
|
||||
@RequestMapping("register")
|
||||
public String signup(String username,String password){
|
||||
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
|
||||
#??????????MyBatis??
|
||||
#??Mybatis?Mapper??
|
||||
mybatis.mapper-locations=classpath:mapper/*.xml
|
||||
mybatis-plus.mapper-locations=classpath:mapper/*.xml
|
||||
#??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