SpringBlade 模糊查询

摘要:
原文:https://sns.bladex.vip/q-1764.htmlhttps://sns.bladex.vip/q -2548. htmlhttps://sns.bladex.vip/q-254.htmlhttps://sns.bladex.vip/q-843.html 1.在前言中,我们看到了开源项目中通知公告的模糊查询和精确匹配之间的区别:地图拾取的参数是模糊bean拾取是精确的。2.默认后台查询方法-fine

原文:
https://sns.bladex.vip/q-1764.html
https://sns.bladex.vip/q-2548.html
https://sns.bladex.vip/q-254.html
https://sns.bladex.vip/q-843.html

一、前言

看开源项目里面的通知公告

模糊查询和精准匹配的区别:

  1. Map去接参数就是模糊
  2. Bean去接就是精准

二、默认的后台查询方法-精准匹配

	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入product")
	public R<IPage<ProductVO>> list(Product product, Query query) {
		IPage<Product> pages = productService.page(Condition.getPage(query), Condition.getQueryWrapper(product));
		return R.data(ProductWrapper.build().pageVO(pages));
	}

三、修改后的查询方法-模糊匹配

	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入product")
	public R<IPage<ProductVO>> list(@ApiIgnore @RequestParam Map<String, Object> product, Query query) {
		if (StrUtil.isBlank(query.getAscs()) && StrUtil.isBlank(query.getDescs())){
			query.setDescs("id");// 默认倒序查询
		}
		IPage<Product> pages = productService.page(Condition.getPage(query), Condition.getQueryWrapper(product, Product.class));
		return R.data(ProductWrapper.build().pageVO(pages));
	}

四、又有精准匹配,又有模糊匹配,混合模式

后台用模糊查询,就只修改前端构造查询条件即可

1、我自己的通用判断规则:

  • 如果列的数据类型为number,那么就精准匹配
  • 如果列的数据类型为string,那么就模糊匹配

2、列的修改

新增属性:

  dataType: "number",// 新增的
  rules: [{
	type: "number",// 新增的
	required: true,
	message: "请输入品牌",
	trigger: "blur"
  }],
{
  label: "品牌",
  prop: "brandId",
  rules: [{
	type: "number",
	required: true,
	message: "请输入品牌",
	trigger: "blur"
  }],
  hide: true,// 在列上隐藏
  type: "select",
  dicUrl: "/api/blade-pms/brand/select",
  props: {
	label: "name",
	value: "id"
  },
  search: true,
  dataType: "number",
},

3、修改后的searchChange方法

  searchChange(params, done) {
	
	// 列的属性 dataType 为 number 时,精准匹配
	let validatenull = this.validatenull;
	let findObject = this.findObject;
	let option = this.option;
	let keys = Object.keys(params);

	keys.forEach(function (key) {
	  const column = findObject(option.column, key);
	  if (column.hasOwnProperty('dataType') && (column["dataType"]==="number")){
		let value = params[key];
		if (!validatenull(value)) {
		  params[key + "_equal"] = value;
		  params[key] = null;
		}
	  }
	});

	this.query = params;
	this.page.currentPage = 1;
	this.onLoad(this.page, params);
	done();
  },

4、修改后的条件构造

      getNewCondition(params, column){// 构造查询条件 后端需支持模糊查询

        // 列的属性 dataType 为 number 时,精准匹配
        let validatenull = this.validatenull;
        let findObject = this.findObject;

        if (validatenull(params)){
          return params;// 查询参数为空 直接返回
        }

        Object.keys(params).forEach(function (key) {
          const obj = findObject(column, key);
          if (obj.hasOwnProperty('dataType') && (obj["dataType"]==="number")){
            let value = params[key];
            if (!validatenull(value)) {
              params[key + "_equal"] = value;
              params[key] = null;
            }
          }
        });

        return params;
      },

具体的使用

      onLoad(page, params = {}) {
        this.loading = true;
        params = this.getNewCondition(params, this.option.column);
        getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
        });
      },

5、前端构造条件预览

	private static final String EQUAL = "_equal";
	private static final String NOT_EQUAL = "_notequal";
	private static final String LIKE = "_like";
	private static final String NOT_LIKE = "_notlike";
	private static final String GT = "_gt";
	private static final String LT = "_lt";
	private static final String DATE_GT = "_dategt";
	private static final String DATE_EQUAL = "_dateequal";
	private static final String DATE_LT = "_datelt";
	private static final String IS_NULL = "_null";
	private static final String NOT_NULL = "_notnull";
	private static final String IGNORE = "_ignore";

SpringBlade 模糊查询第1张

6、前端又改造了一下

增加的属性是这样:match: "equal",
SpringBlade 模糊查询第2张

searchChange方法:

      searchChange(params, done) {
        let validatenull = this.validatenull;
        let findObject = this.findObject;
        let option = this.option;
        let keys = Object.keys(params);

        keys.forEach(function (key) {
          const column = findObject(option.column, key);
          if (column.hasOwnProperty('match')) {
            let value = params[key];
            if (!validatenull(value)) {
              params[key + "_" + column["match"]] = value;// 如:_equal
              params[key] = null;
            }
          }
        });

        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
      },

SpringBlade 模糊查询第3张

免责声明:文章转载自《SpringBlade 模糊查询》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇BigDecimalPCRE函数简介和使用示例【转】下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

EwoMail 开源邮件服务器安装教程

本教程示例中使用的主要域名是ewomail.cn。设置主机名EwoMail将在安装后默认使用带有域名前缀mail的主机名。例如,mail.ewomail。cn将系统主机名更改为mail.ewomail.cn。查看当前主机名hostname-f修改主机名,修改文件/etc/sysconfig/network修改文件/etc/hosts,添加mail.ewoma...

数据库软考易混淆知识之信息化基础、项目管理

2、 关键路径关键路径是活动图中最长的路径示例:图中显示了软件项目的活动图,其中固定点表示项目里程碑,连接顶点的边表示包含的活动,边上的数字表示活动持续时间的天数,则完成项目的最短时间为()天,活动EH和IJ的放松时间分别为()日。...

愿你走出半生,归来仍是Java Parser

几天前,我的一个朋友给了我一个Haskell问题嘿,MK。假设我有一个BNF,我在Haskell中有一个这个BNF的解析器。现在,我想为这个BNF换一条线。是否有任何方法可以在不接触BNF解析器代码的情况下扩展BNF解析器?让我们想想,这个x是什么样的变体?请记住,传入的参数不是self,而是super。好了,openrecursion已经准备好了,剩下的是...

获取用户当前位置信息的两种方法——H5、微信

在之前调用百度地图API的总结中,我使用H5获取了当前位置信息。事实上,微信还提供了一种获取用户地理位置的方法。现在我们将发布这两种方法,并根据情况选择使用它们。varspeed=响应。速度;//速度,单位:米/秒varaccuracy=res精度;//位置精度}});3、 从地理位置和地图显示中获得的经度和纬度可以使用百度地图或高德地图显示,也可以在微信内...

实用小技巧:在键盘没有小键盘时怎么打开任务管理器

原创:转载请注明出处!我需要为我的工作买一个87键的机械键盘。当我打开任务管理器打开时,我经常使用Ctrl+Alt+;现在不行了。有几种方法可以打开任务管理器以查看当前任务状态:1.Ctrl+Alt+Delete,这与之前的Ctrl+Alt+Delete相同,效果相同;2.Ctrl+Shift+Esc也可以调出任务管理器;3.右键单击任务栏的空白区域,然后从...

Vue中在移动端如何判断设备是安卓还是ios

u、 匹配(/(i[^;]+;(U;)?CPU+MacOSX/);如果(isiOS){return“ios”;}否则{return“android”;}},...