layui table实现多条件搜索

版权声明:请勿用于任何商业用途,转载请说明出处!

百度了好多文章,效果都不是很满意,最终还是需要自己动手!经过不断的测试,终于做出来了!

2021.06.30:之前的思路无法解决前端分页问题,代码做了下修改!

先展示下效果:

1.页面无条件初始化

layui table实现多条件搜索_第1张图片

2.搜索条件查询结果

layui table实现多条件搜索_第2张图片

源码:

1.前端页面代码:




    
用户信息

2.服务端

2.1 controller、service层代码:

// controller层findPage
@RequiresPermissions("user:view")
    @RequestMapping("/findPage")
    @ResponseBody
    public IPage findPage(@RsaSecurityParameter User user){
        return userService.findPage(user);
    }


//service层findPage
public IPage findPage( User entity, String... args) {
        Map search = null;
        if (EmptyUtil.isNoEmpty(entity.getUserName())
                || EmptyUtil.isNoEmpty(entity.getLoginCode())
        ){
            search = new HashedMap();
            if (EmptyUtil.isNoEmpty(entity.getUserName())){
                search.put("USER_NAME" , entity.getUserName());
            }
            if (EmptyUtil.isNoEmpty(entity.getLoginCode())){
                search.put("LOGIN_CODE" , entity.getLoginCode());
            }
        }else {
            long limit = entity.getLimit();
            long page = entity.getPage();
            entity = new User();
            entity.setLimit(limit);
            entity.setPage(page);
        }
        return super.findPage(entity , search , args);
    }

//service父类中的findPage
  public IPage findPage(T entity , Map search , String... args){
        long current = 1L;
        long size = 10L;
        current =  EmptyUtil.isNoEmpty(ReflexUtil.getFieldValue(entity , "page"))?(long) ReflexUtil.getFieldValue(entity , "page") :current;
        size = EmptyUtil.isNoEmpty(ReflexUtil.getFieldValue(entity , "limit"))? (long) ReflexUtil.getFieldValue(entity , "limit") :size;
        QueryWrapper queryWrapper;
        if (EmptyUtil.isNoEmpty(search)){
            queryWrapper = new QueryWrapper<>();
            for (Map.Entry entry:search.entrySet()
                 ) {
                queryWrapper.like(entry.getKey() , entry.getValue());
            }
        }else {
            queryWrapper = new QueryWrapper<>(entity);
        }
        queryWrapper.orderByAsc(args);
        return super.page(new Page(current , size) , queryWrapper);
    }

2.2 实体类需要limit、size属性用于接收前端传入的分页信息

public class User extends PageEntity  //User实体类继承一个自定义的page父类



// 自定义page父类
@ToString
@NoArgsConstructor
public class PageEntity extends BaseEntity {
    private static final long serialVersionUID = -8596775877393206795L;

    @TableField(exist = false)
    @Setter
    @Getter
    protected long limit;
    @TableField(exist = false)
    @Setter
    @Getter
    protected long page;


}

你可能感兴趣的:(JavaScript)