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

View File

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