Initial commit

This commit is contained in:
Yo Vinchen 2023-03-17 22:36:45 +08:00
parent f8801cdef6
commit 113b034afb
4 changed files with 125 additions and 7 deletions

View File

@ -0,0 +1,52 @@
package com.yv.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yv.admain.Book;
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
*/
@RestController
@RequestMapping("/books")
public class BookController {
@Autowired
private IBookService bookService;
@GetMapping
public List<Book> getAll() {
return bookService.list();
}
@PostMapping
public Boolean save(@RequestBody Book book) {
return bookService.save(book);
}
@PutMapping
public Boolean update(@RequestBody Book book) {
return bookService.modify(book);
}
@DeleteMapping("{id}")
public Boolean detect(@PathVariable Integer id) {
return bookService.delete(id);
}
@GetMapping("{id}")
public Book getById(@PathVariable Integer id) {
return bookService.getById(id);
}
@GetMapping("{currentPage}/{pageSize}")
public IPage<Book> getPage(@PathVariable int currentPage,@PathVariable int pageSize) {
return bookService.getPage(currentPage, pageSize);
}
}

View File

@ -0,0 +1,53 @@
package com.yv.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yv.admain.Book;
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
*/
//注释掉不启动此Controller
//@RestController
@RequestMapping("/books")
public class BookController2 {
@Autowired
private IBookService bookService;
@GetMapping
public List<Book> getAll() {
return bookService.list();
}
@PostMapping
public Boolean save(@RequestBody Book book) {
return bookService.save(book);
}
@PutMapping
public Boolean update(@RequestBody Book book) {
return bookService.modify(book);
}
@DeleteMapping("{id}")
public Boolean detect(@PathVariable Integer id) {
return bookService.delete(id);
}
@GetMapping("{id}")
public Book getById(@PathVariable Integer id) {
return bookService.getById(id);
}
@GetMapping("{currentPage}/{pageSize}")
public IPage<Book> getPage(@PathVariable int currentPage,@PathVariable int pageSize) {
return bookService.getPage(currentPage, pageSize);
}
}

View File

@ -0,0 +1,13 @@
package com.yv.controller.utils;
import lombok.Data;
/**
* @author YoVinchen
* @date 2023/3/17 下午 8:49
*/
@Data
public class R {
private Boolean flag;
private Object data;
}