@Mapper
public interface BookDao extends BaseMapper {
新增bookdao.insert(book);
修改bookdao.updateById(book);
删除bookdao.deleteById(id);
查所有bookdao.selectList(null);
//分页查
IPage page= new Page(1,5);
bookdao.selectPage(page,null);
page.getPages();//一共几页
page.getRecords();//当前页的数据
page.Current();//当前页
page.Total();//一共几条
page.Size();//一页几条
@Configuration
public class MPConfig { // mp拦截器
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); //这个是专门用来做分页的拦截器
return interceptor;
}
}
条件查询
QueryWrapper<Book> qw = new QueryWrapper<>();
qw.like("a"!=null,"name","a"); 查全部带a的 第一个参数可省trun
qw.eq("name","a"); 查name=a
qw.ne("name","a"); 查name!=a qw间and
....
LambdaQueryWrapper<Book> qw = new LambdaQueryWrapper<>();
qw.like(Book::getName,"a"); 查全部带a的
bookDao.selectList(qw);
public interface BookService extends IService<Book> {
@Service
public class BookServiceImpl extends ServiceImpl<BookDao,Book> implements BookService {
bookService.getById(id);
bookService.updateById(book);
bookService.removeById(id);
bookService.list(); //查所有
IPage page= new Page(1,5);
bookService.page(page); //分页查