Jeecg高级查询前后端实现使用文档


Jeecg高级查询前端构造器,具体Vue代码在前端页面JSuperQuery中,下方是使用demo

1.在适合的地方放入标签

<j-super-query :fieldList="fieldList" @handleSuperQuery="handleSuperQuery"/>

2.参数配置

参数  类型 必填 说明
fieldList array 需要查询的列集合示例如下,type类型有:date/datetime/string/int/number
callback array   回调函数名称(非必须)默认handleSuperQuery

3.fieldList结构示例:

fieldList:[
        {
          type: "string",
          value: "name",
          text: "姓名"
        }, {
          type: "date",
          value: "birthday",
          text: "生日"
        }, {
          type: "int",
          value: "age",
          text: "年龄"
        }
]

4.页面代码概述:

//插入代码后 components
import JSuperQuery from "@comp/jeecg/JSuperQuery";
export default {
  name:'testJSuperQuery',
  components:{
  JSuperQuery,
}
}

5.list页面data中定义属性

fieldList:[ { type: "string", value: "name", text: "姓名" }, { type: "date", value: "birthday", text: "生日" }, { type: "int", value: "age", text: "年龄" }],
superQueryFlag:false,
superQueryParams:"",
superQueryMatchType:"",

6.list页面声明回调函数 handleSuperQuery(默认)

//官方文档中没有matchType,导致matchType进入后台无论是"and"或者是"or"都显示"and",下方是已解决方案
handleSuperQuery(arg,matchType) { if(!arg){ this.superQueryParams='' this.superQueryFlag = false }else{ this.superQueryFlag = true this.superQueryParams=JSON.stringify(arg) this.superQueryMatchType = matchType }      this.loadData(1) }

7.改造list页面方法 //要分清查询是查询 高级查询是高级查询 方法不是同一个

searchQuery() {
      let sqp = {}
      if(this.superQueryParams){
        sqp['superQueryParams']=encodeURI(this.superQueryParams)
        sqp['superQueryMatchType'] = this.superQueryMatchType //这一行是官方文档中不存在的
      }
      var param = Object.assign(sqp, this.queryParam, this.isorter ,this.filters);
      param.field = this.getQueryField();
      param.pageNo = this.ipagination.current;
      param.pageSize = this.ipagination.pageSize;
      return filterObj(param); //使用filterObj方法需要 import {filterObj} from "location"
    },

8.后台Mybatis-plus使用

//切记需使用Mybatis-plus
public Result> superQuery(Entity entity, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,HttpServletRequest req) { Result> result = new Result<>(); QueryWrapper wrapper = QueryGenerator.initQueryWrapper(entity, req.getParameterMap()); Page page = new Page<>(pageNo, pageSize); Page pageList = service.page(page, wrapper); result.setSuccess(true); result.setResult(pageList); return result; }