From 1da4fb72d1ad29d465e9077d402d4d3f74553200 Mon Sep 17 00:00:00 2001 From: smallchill Date: Mon, 20 Jan 2020 12:48:43 +0800 Subject: [PATCH] =?UTF-8?q?:tada:=20getQueryWrapper=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E6=8E=92=E9=99=A4=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/mp/support/Condition.java | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/blade-core-mybatis/src/main/java/org/springblade/core/mp/support/Condition.java b/blade-core-mybatis/src/main/java/org/springblade/core/mp/support/Condition.java index d684311..198a199 100644 --- a/blade-core-mybatis/src/main/java/org/springblade/core/mp/support/Condition.java +++ b/blade-core-mybatis/src/main/java/org/springblade/core/mp/support/Condition.java @@ -18,6 +18,8 @@ package org.springblade.core.mp.support; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.springblade.core.launch.constant.TokenConstant; +import org.springblade.core.tool.support.Kv; import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.Func; @@ -33,8 +35,8 @@ public class Condition { /** * 转化成mybatis plus中的Page * - * @param query 查询包装类 - * @return Page T + * @param query 查询条件 + * @return IPage */ public static IPage getPage(Query query) { Page page = new Page<>(Func.toInt(query.getCurrent(), 1), Func.toInt(query.getSize(), 10)); @@ -46,8 +48,8 @@ public class Condition { /** * 获取mybatis plus中的QueryWrapper * - * @param entity 实体类 - * @param 泛型 + * @param entity 实体 + * @param 类型 * @return QueryWrapper */ public static QueryWrapper getQueryWrapper(T entity) { @@ -57,16 +59,28 @@ public class Condition { /** * 获取mybatis plus中的QueryWrapper * - * @param query 查询包装类 + * @param query 查询条件 * @param clazz 实体类 - * @param 泛型 + * @param 类型 * @return QueryWrapper */ public static QueryWrapper getQueryWrapper(Map query, Class clazz) { - query.remove("current"); - query.remove("size"); - query.remove("ascs"); - query.remove("descs"); + Kv exclude = Kv.init().set(TokenConstant.HEADER, TokenConstant.HEADER) + .set("current", "current").set("size", "size").set("ascs", "ascs").set("descs", "descs"); + return getQueryWrapper(query, exclude, clazz); + } + + /** + * 获取mybatis plus中的QueryWrapper + * + * @param query 查询条件 + * @param exclude 排除的查询条件 + * @param clazz 实体类 + * @param 类型 + * @return QueryWrapper + */ + public static QueryWrapper getQueryWrapper(Map query, Map exclude, Class clazz) { + exclude.forEach((k, v) -> query.remove(k)); QueryWrapper qw = new QueryWrapper<>(); qw.setEntity(BeanUtil.newInstance(clazz)); SqlKeyword.buildCondition(query, qw);