首页 > 其他分享 >plus

plus

时间:2022-11-16 15:12:50浏览次数:40  
标签:分页 查询 Field bean plus page size

目录

分页查询

  • 视图层用对象接所有参数(c工程,YqOpinionController.java)
点击查看代码


 @ApiOperation(value = "多条件分页查询",notes = "<b style='color:red'>参数为空,执行列表分页查询;参数有值,为带条件分页;code:0,data:null,代表查询无数据</b>")
    @GetMapping("/page")
    @SuppressWarnings("all")
    public ViewResult<IPage<YqOpinion>> findPage(YqOpinionDto bean,
                                                 @RequestParam(name = "size", defaultValue = "10") Integer size,
                                                 @RequestParam(name = "current", defaultValue = "1") Integer current) {
        IPage page = new Page(current, size);

        if(isFieldsEmpty(bean)) {
            // 无任何查询条件
            QueryWrapper queryWrapper = new QueryWrapper();
            return ViewResult.success(yqOpinionService.page(page, queryWrapper));
        }
  • 检查对象属性是否有带查询数据
点击查看代码
 /**
     * 没带任何查询条件
     *
     * @param bean
     * @return true :没带任何查询条件,false: 有带查询条件
     */
    private boolean isFieldsEmpty(YqOpinionDto bean) {
        boolean fieldsEmpty = true;

        Class<? extends YqOpinionDto> clazz = bean.getClass();
        Field[] fields = clazz.getDeclaredFields();
        for (Field fd:fields) {
            try {
                Field f = clazz.getDeclaredField(fd.getName());
                f.setAccessible(true);
                Object fieldVal = f.get(bean);
                if(ObjectUtils.isNotEmpty(fieldVal)) {
                    fieldsEmpty = false;
                    break;
                }
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }

        }
        return fieldsEmpty;
    }

标签:分页,查询,Field,bean,plus,page,size
From: https://www.cnblogs.com/jf666/p/16895956.html

相关文章