querywrapper 다중 조건 조회

21654 단어 프레임
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>

좋은 웹페이지 즐겨찾기