简单德导包省略
分页运用的pagehelper插件。完全不用写sql语句
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wei.pojo.File;
import com.wei.service.FileService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.sql.Wrapper;
import java.util.List;
import java.util.Map;
/**
* @author weijq
* @since 2021-03-29
*/
@RestController
@RequestMapping("/file")
public class FileController {
@Autowired
private FileService fileService;
/**
* 模糊查询加分页
* @param pageNum
* @param pageSize
* @param fileName
* @return
*/
@GetMapping("likeFind")
public PageInfo likeFind(@RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
@RequestParam(value = "pageSize",required = false,defaultValue = "2")Integer pageSize,
String fileName){
QueryWrapper<Object> queryWrapper = new QueryWrapper<>();
queryWrapper.like("file_name",fileName);
System.out.println(queryWrapper);
PageHelper.startPage(pageNum,pageSize);
List<File> files = fileService.likeFind(queryWrapper);
System.out.println(files);
PageInfo<File> pageInfo = new PageInfo<>(files);
return pageInfo;
}
/**
* 实现多条件模糊查询
* @param pageNum
* @param pageSize
* @param fileName 模糊条件
* @param fileZhaiyao 模糊条件
* @return
*/
@RequestMapping("selectMapsByPage")
public PageInfo selectMaps(@RequestParam(value = "pageNum",defaultValue = "1",required = false) Integer pageNum,
@RequestParam(value = "pageSize",defaultValue = "2",required = false) Integer pageSize,
String fileName,String fileZhaiyao){
QueryWrapper<File> queryWrapper = new QueryWrapper<>();
queryWrapper = new QueryWrapper();
if (""!=fileName&&fileName!=null){
queryWrapper.like("file_name",fileName);
}
if (""!=fileZhaiyao&&fileZhaiyao!=null){
queryWrapper.like("file_zhaiyao",fileZhaiyao);
}
PageHelper.startPage(pageNum,pageSize);
List<Map<String, Object>> list = fileService.selectMaps(queryWrapper);
PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
return pageInfo;
}
}
springboot整合mybatis-plus多条件模糊查询及分页
最新推荐文章于 2024-09-30 10:13:27 发布