Initial commit

This commit is contained in:
Yo Vinchen 2023-03-17 22:49:51 +08:00
parent 113b034afb
commit f53fd046d0
2 changed files with 25 additions and 15 deletions

View File

@ -1,13 +1,11 @@
package com.yv.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yv.admain.Book;
import com.yv.controller.utils.R;
import com.yv.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author YoVinchen
* @date 2023/3/17 下午 8:00
@ -20,33 +18,34 @@ public class BookController {
private IBookService bookService;
@GetMapping
public List<Book> getAll() {
return bookService.list();
public R getAll() {
return new R(true, bookService.list());
}
@PostMapping
public Boolean save(@RequestBody Book book) {
return bookService.save(book);
public R save(@RequestBody Book book) {
return new R(bookService.save(book));
}
@PutMapping
public Boolean update(@RequestBody Book book) {
return bookService.modify(book);
public R update(@RequestBody Book book) {
return new R(bookService.modify(book));
}
@DeleteMapping("{id}")
public Boolean detect(@PathVariable Integer id) {
return bookService.delete(id);
public R detect(@PathVariable Integer id) {
return new R(bookService.delete(id));
}
@GetMapping("{id}")
public Book getById(@PathVariable Integer id) {
return bookService.getById(id);
public R getById(@PathVariable Integer id) {
return new R(true, bookService.getById(id));
}
@GetMapping("{currentPage}/{pageSize}")
public IPage<Book> getPage(@PathVariable int currentPage,@PathVariable int pageSize) {
return bookService.getPage(currentPage, pageSize);
public R getPage(@PathVariable int currentPage, @PathVariable int pageSize) {
return new R(true, bookService.getPage(currentPage, pageSize));
}
}

View File

@ -10,4 +10,15 @@ import lombok.Data;
public class R {
private Boolean flag;
private Object data;
public R(){};
public R(Boolean flag) {
this.flag = flag;
}
public R(Boolean flag,Object data){
this.flag = flag;
this.data = data;
}
}