Initial commit
This commit is contained in:
		@@ -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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -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;
 | 
			
		||||
}
 | 
			
		||||
@@ -38,19 +38,19 @@ public class BookServiceImpl extends ServiceImpl<BookDao, Book> implements IBook
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public IPage<Book> getPage(int currentPage, int pageSize) {
 | 
			
		||||
        IPage page = new Page(currentPage,pageSize);
 | 
			
		||||
        bookDao.selectPage(page,null);
 | 
			
		||||
        IPage page = new Page(currentPage, pageSize);
 | 
			
		||||
        bookDao.selectPage(page, null);
 | 
			
		||||
        return page;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public IPage<Book> getPage(int currentPage, int pageSize, Book book) {
 | 
			
		||||
        LambdaQueryWrapper<Book> lqw = new LambdaQueryWrapper<Book>();
 | 
			
		||||
        lqw.like(Strings.isNotEmpty(book.getType()),Book::getType,book.getType());
 | 
			
		||||
        lqw.like(Strings.isNotEmpty(book.getName()),Book::getName,book.getName());
 | 
			
		||||
        lqw.like(Strings.isNotEmpty(book.getDescription()),Book::getDescription,book.getDescription());
 | 
			
		||||
        IPage page = new Page(currentPage,pageSize);
 | 
			
		||||
        bookDao.selectPage(page,lqw);
 | 
			
		||||
        lqw.like(Strings.isNotEmpty(book.getType()), Book::getType, book.getType());
 | 
			
		||||
        lqw.like(Strings.isNotEmpty(book.getName()), Book::getName, book.getName());
 | 
			
		||||
        lqw.like(Strings.isNotEmpty(book.getDescription()), Book::getDescription, book.getDescription());
 | 
			
		||||
        IPage page = new Page(currentPage, pageSize);
 | 
			
		||||
        bookDao.selectPage(page, lqw);
 | 
			
		||||
        return page;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user