querywrapper多条件查询

concroller:

/**
    * 查询列表
    * @return
    */
    @ApiResponses({@ApiResponse(code = 200, message = "正常", response = SourceMateria.class)})
    @ApiOperation(value="全部查询")
    @GetMapping
    public AjaxResult selectAll(@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                @ApiParam(name="id", value="素材id(根据id查询)")@RequestParam(value = "id", required=false)Long id,
                                @ApiParam(name="screenId", value="筛选条件号:1001=最新,1002=最热,1003=免费,1004=付费")@RequestParam(value = "screenId", required=false)Integer screenId,
                                @ApiParam(name="typeId", value="素材类型id(根据类型查询)")@RequestParam(value = "typeId", required=false)Long typeId,
                                @ApiParam(name="title", value="素材标题(根据标题模糊查询)")@RequestParam(value = "title", required=false)String title) {
        Page<SourceMateria> page = new Page<SourceMateria>(pageNo, pageSize);
        QueryWrapper<SourceMateria> queryWrapper=new QueryWrapper<>();
        if(id!=null&&id>0){
            queryWrapper=queryWrapper.eq("t_source_materia.id",id);
            //添加访问量
            SourceMateria sourceMateria = sourceMateriaService.selectById(id);
            sourceMateria.setTraffic(sourceMateria.getTraffic()+1);
            sourceMateriaService.updateById(sourceMateria);
        }
        if(typeId!=null&&typeId>0){
            queryWrapper=queryWrapper.eq("t_source_materia_type.id",typeId);
        }
        if(title!=null&&title!=""){
            queryWrapper=queryWrapper.like("t_source_materia.title",title);
        }
        if(screenId!=null&&screenId>0){
            switch (screenId){
                case 1001: queryWrapper=queryWrapper.orderByDesc("create_time");
                    break;
                case 1002: queryWrapper=queryWrapper.orderByDesc("share_number");
                    break;
                case 1003: queryWrapper=queryWrapper.eq("smart_coin",0);
                    break;
                case 1004: queryWrapper=queryWrapper.gt("smart_coin",0);
                    break;
                default:
                    break;
            }
        }
        IPage<SourceMateria> pageInfo = sourceMateriaService.restListPage(queryWrapper,page);
        List<SourceMateriaType> sourceMateriaTypes = sourceMateriaTypeService.selectList(null);
        Map<String, Object> map = new HashMap<>();
        map.put("pageInfo",new PageInfo(pageInfo));
        map.put("allType",sourceMateriaTypes);
        return AjaxResult.success(map);
    }

IService :

/**
     * 接口查询分页列表
     * @param queryWrapper
     * @param page
     * @return
     */
    IPage<SourceMateria> restListPage(QueryWrapper<SourceMateria> queryWrapper, IPage page);

ServiceImpl :

/**
     * 接口查询分页列表
     * @param queryWrapper
     * @param page
     * @return
     */
    @Override
    public IPage<SourceMateria> restListPage(QueryWrapper<SourceMateria> queryWrapper, IPage page) {
        return page.setRecords(sourceMateriaMapper.restListPage(queryWrapper,page));
    }

Mapper :

List<SourceMateria> restListPage(@Param(Constants.WRAPPER) QueryWrapper<SourceMateria> queryWrapper, IPage<SourceMateria> page);

XML :

<select id="restListPage" resultType="com.mbyte.easy.admin.entity.SourceMateria">
        SELECT
        t_source_materia.id,
        t_source_materia.source_id,
        t_source_materia_type.name as name,
        t_source_materia.Icon,
        t_source_materia.title,
        t_source_materia.content,
        t_source_materia.video_url,
        t_source_materia.smart_coin,
        t_source_materia.traffic,
        t_source_materia.share_number,
        t_source_materia.is_goods,
        t_source_materia.create_time,
        t_source_materia.update_time
        FROM
        t_source_materia
        INNER JOIN t_source_materia_type ON t_source_materia.source_id = t_source_materia_type.id
        ${ew.customSqlSegment} //querywrapper导入
    </select>

你可能感兴趣的:(框架)