springboot整合mybatis-plus多条件模糊查询及分页


简单德导包省略
分页运用的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;
    }
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值