From f5d7aff146ad0321815d4cce13cb396e6ad2cb7c Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Mon, 1 Feb 2021 02:06:14 +0800 Subject: [PATCH] update --- .../mybatisplus/base/MyBaseServiceImpl.java | 1 - .../mybatisplus/injector/MySqlInjector.java | 1 + .../github/mybatisplus/method/SqlMethod.java | 2 +- .../mybatisplus/query/interfaces/MyJoin.java | 7 +- .../github/mybatisplus/toolkit/Constant.java | 3 + .../wrapper/MyAbstractLambdaWrapper.java | 21 +---- .../wrapper/MyAbstractWrapper.java | 20 +---- .../wrapper/MyLambdaQueryWrapper.java | 54 ++++++------- .../wrapper/interfaces/MyCompare.java | 81 +++++++------------ .../wrapper/interfaces/MyFunc.java | 20 +---- .../wrapper/interfaces/MyLambdaJoin.java | 3 + .../wrapper/interfaces/MySFunctionQuery.java | 15 ---- 12 files changed, 74 insertions(+), 154 deletions(-) diff --git a/src/main/java/com/github/mybatisplus/base/MyBaseServiceImpl.java b/src/main/java/com/github/mybatisplus/base/MyBaseServiceImpl.java index c279194..41f4f2e 100644 --- a/src/main/java/com/github/mybatisplus/base/MyBaseServiceImpl.java +++ b/src/main/java/com/github/mybatisplus/base/MyBaseServiceImpl.java @@ -2,7 +2,6 @@ package com.github.mybatisplus.base; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.github.mybatisplus.wrapper.MyLambdaQueryWrapper; import com.github.mybatisplus.wrapper.MyWrapper; import java.util.List; diff --git a/src/main/java/com/github/mybatisplus/injector/MySqlInjector.java b/src/main/java/com/github/mybatisplus/injector/MySqlInjector.java index 8916952..86b6ee6 100644 --- a/src/main/java/com/github/mybatisplus/injector/MySqlInjector.java +++ b/src/main/java/com/github/mybatisplus/injector/MySqlInjector.java @@ -9,6 +9,7 @@ import java.util.List; /** * SQL 注入器 * + * @author yulichang * @see DefaultSqlInjector */ public class MySqlInjector extends DefaultSqlInjector { diff --git a/src/main/java/com/github/mybatisplus/method/SqlMethod.java b/src/main/java/com/github/mybatisplus/method/SqlMethod.java index fb2209c..4e1e4a7 100644 --- a/src/main/java/com/github/mybatisplus/method/SqlMethod.java +++ b/src/main/java/com/github/mybatisplus/method/SqlMethod.java @@ -30,7 +30,7 @@ public enum SqlMethod { ""), SELECT_JOIN_MAPS_PAGE("selectJoinMapsPage", "返回Map集合并分页", - ""); + ""); private final String method; private final String desc; diff --git a/src/main/java/com/github/mybatisplus/query/interfaces/MyJoin.java b/src/main/java/com/github/mybatisplus/query/interfaces/MyJoin.java index 559693b..52127fe 100644 --- a/src/main/java/com/github/mybatisplus/query/interfaces/MyJoin.java +++ b/src/main/java/com/github/mybatisplus/query/interfaces/MyJoin.java @@ -2,6 +2,9 @@ package com.github.mybatisplus.query.interfaces; import com.github.mybatisplus.toolkit.Constant; +/** + * @author yulichang + */ public interface MyJoin { default Children leftJoin(String joinSql) { @@ -16,7 +19,7 @@ public interface MyJoin { return rightJoin(true, joinSql); } - default Children rightJoin(boolean condition, String joinSql){ + default Children rightJoin(boolean condition, String joinSql) { return join(Constant.RIGHT_JOIN, condition, joinSql); } @@ -24,7 +27,7 @@ public interface MyJoin { return innerJoin(true, joinSql); } - default Children innerJoin(boolean condition, String joinSql){ + default Children innerJoin(boolean condition, String joinSql) { return join(Constant.INNER_JOIN, condition, joinSql); } diff --git a/src/main/java/com/github/mybatisplus/toolkit/Constant.java b/src/main/java/com/github/mybatisplus/toolkit/Constant.java index 880ab2a..7431306 100644 --- a/src/main/java/com/github/mybatisplus/toolkit/Constant.java +++ b/src/main/java/com/github/mybatisplus/toolkit/Constant.java @@ -11,6 +11,8 @@ public interface Constant { */ String TABLE_ALIAS = "t"; + String AS = " AS "; + String ON = " ON "; String EQUALS = " = "; @@ -39,4 +41,5 @@ public interface Constant { * " INNER JOIN " */ String INNER_JOIN = StringPool.SPACE + INNER + StringPool.SPACE + JOIN + StringPool.SPACE; + } diff --git a/src/main/java/com/github/mybatisplus/wrapper/MyAbstractLambdaWrapper.java b/src/main/java/com/github/mybatisplus/wrapper/MyAbstractLambdaWrapper.java index cfc0543..6d0162d 100644 --- a/src/main/java/com/github/mybatisplus/wrapper/MyAbstractLambdaWrapper.java +++ b/src/main/java/com/github/mybatisplus/wrapper/MyAbstractLambdaWrapper.java @@ -1,18 +1,3 @@ -/* - * Copyright (c) 2011-2021, baomidou (jobob@qq.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package com.github.mybatisplus.wrapper; import com.baomidou.mybatisplus.core.metadata.TableInfo; @@ -33,11 +18,7 @@ import java.util.Map; import static java.util.stream.Collectors.joining; /** - * Lambda 语法使用 Wrapper - *

统一处理解析 lambda 获取 column

- * - * @author hubin miemie HCL - * @since 2017-05-26 + * copy {@link com.baomidou.mybatisplus.core.conditions.AbstractLambdaWrapper} */ @SuppressWarnings("serial") public abstract class MyAbstractLambdaWrapper> diff --git a/src/main/java/com/github/mybatisplus/wrapper/MyAbstractWrapper.java b/src/main/java/com/github/mybatisplus/wrapper/MyAbstractWrapper.java index 72f7a93..fe3dbb8 100644 --- a/src/main/java/com/github/mybatisplus/wrapper/MyAbstractWrapper.java +++ b/src/main/java/com/github/mybatisplus/wrapper/MyAbstractWrapper.java @@ -1,18 +1,3 @@ -/* - * Copyright (c) 2011-2021, baomidou (jobob@qq.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package com.github.mybatisplus.wrapper; import com.baomidou.mybatisplus.core.conditions.ISqlSegment; @@ -43,10 +28,7 @@ import static com.baomidou.mybatisplus.core.enums.WrapperKeyword.APPLY; import static java.util.stream.Collectors.joining; /** - * 查询条件封装 - * - * @author hubin miemie HCL - * @since 2017-05-26 + * copy {@link com.baomidou.mybatisplus.core.conditions.AbstractWrapper} */ @SuppressWarnings({"serial", "unchecked"}) public abstract class MyAbstractWrapper> extends MyWrapper diff --git a/src/main/java/com/github/mybatisplus/wrapper/MyLambdaQueryWrapper.java b/src/main/java/com/github/mybatisplus/wrapper/MyLambdaQueryWrapper.java index 2ad6f9f..2039304 100644 --- a/src/main/java/com/github/mybatisplus/wrapper/MyLambdaQueryWrapper.java +++ b/src/main/java/com/github/mybatisplus/wrapper/MyLambdaQueryWrapper.java @@ -1,18 +1,3 @@ -/* - * Copyright (c) 2011-2021, baomidou (jobob@qq.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package com.github.mybatisplus.wrapper; import com.baomidou.mybatisplus.core.conditions.SharedString; @@ -25,10 +10,10 @@ import com.baomidou.mybatisplus.core.toolkit.Assert; import com.baomidou.mybatisplus.core.toolkit.StringPool; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; -import com.github.mybatisplus.wrapper.interfaces.MyLambdaJoin; -import com.github.mybatisplus.wrapper.interfaces.MySFunctionQuery; import com.github.mybatisplus.toolkit.Constant; import com.github.mybatisplus.toolkit.MyLambdaUtils; +import com.github.mybatisplus.wrapper.interfaces.MyLambdaJoin; +import com.github.mybatisplus.wrapper.interfaces.MySFunctionQuery; import java.util.ArrayList; import java.util.List; @@ -38,10 +23,7 @@ import java.util.function.Predicate; import java.util.stream.Collectors; /** - * Lambda 语法使用 Wrapper - * - * @author hubin miemie HCL - * @since 2017-05-26 + * copy {@link com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper} */ @SuppressWarnings("serial") public class MyLambdaQueryWrapper extends MyAbstractLambdaWrapper> @@ -57,7 +39,6 @@ public class MyLambdaQueryWrapper extends MyAbstractLambdaWrapper extends MyAbstractLambdaWrapper s : columns) { Class clazz = MyLambdaUtils.getEntityClass(s); TableInfo info = TableInfoHelper.getTableInfo(clazz); - selectColumns.add(new SelectColumn(clazz, info.getTableName(), MyLambdaUtils.getColumn(s))); + selectColumns.add(new SelectColumn(clazz, info.getTableName(), MyLambdaUtils.getColumn(s), null)); } } return typedThis; @@ -129,15 +110,25 @@ public class MyLambdaQueryWrapper extends MyAbstractLambdaWrapper selectColumns.add(new SelectColumn(entityClass, info.getTableName(), i.getColumn()))); + i -> selectColumns.add(new SelectColumn(entityClass, info.getTableName(), i.getColumn(), null))); return typedThis; } + public final MyLambdaQueryWrapper selectAs(SFunction columns, SFunction alias) { + Class clazz = MyLambdaUtils.getEntityClass(columns); + TableInfo info = TableInfoHelper.getTableInfo(clazz); + selectColumns.add(new SelectColumn(clazz, info.getTableName(), MyLambdaUtils.getColumn(columns), MyLambdaUtils.getName(alias))); + return typedThis; + } + @Override public String getSqlSelect() { if (StringUtils.isBlank(sqlSelect.getStringValue())) { - String s = selectColumns.stream().map(i -> i.getTableName() + StringPool.DOT + i.getColumnName()).collect(Collectors.joining(StringPool.COMMA)); + String s = selectColumns.stream().map(i -> + i.getTableName() + StringPool.DOT + i.getColumnName() + + (StringUtils.isBlank(i.getAlias()) ? StringPool.EMPTY : (Constant.AS + i.getAlias()))) + .collect(Collectors.joining(StringPool.COMMA)); sqlSelect.setStringValue(s); } return sqlSelect.getStringValue(); @@ -198,14 +189,15 @@ public class MyLambdaQueryWrapper extends MyAbstractLambdaWrapper clazz, String tableName, String columnName) { + public SelectColumn(Class clazz, String tableName, String columnName, String alias) { this.clazz = clazz; this.tableName = tableName; this.columnName = columnName; + this.alias = alias; } - public Class getClazz() { return clazz; } @@ -229,5 +221,13 @@ public class MyLambdaQueryWrapper extends MyAbstractLambdaWrapper比较值

- * - * @author hubin miemie HCL - * @since 2017-05-26 + * {@link com.baomidou.mybatisplus.core.conditions.interfaces.Compare} */ public interface MyCompare extends Serializable { /** * ignore */ - default Children allEq(Map, V> params) { + default Children allEq(Map, V> params) { return allEq(params, true); } /** * ignore */ - default Children allEq(Map, V> params, boolean null2IsNull) { + default Children allEq(Map, V> params, boolean null2IsNull) { return allEq(true, params, null2IsNull); } @@ -52,19 +33,19 @@ public interface MyCompare extends Serializable { * @param null2IsNull 是否参数为 null 自动执行 isNull 方法, false 则忽略这个字段\ * @return children */ - Children allEq(boolean condition, Map, V> params, boolean null2IsNull); + Children allEq(boolean condition, Map, V> params, boolean null2IsNull); /** * ignore */ - default Children allEq(BiPredicate, V> filter, Map, V> params) { + default Children allEq(BiPredicate, V> filter, Map, V> params) { return allEq(filter, params, true); } /** * ignore */ - default Children allEq(BiPredicate, V> filter, Map, V> params, boolean null2IsNull) { + default Children allEq(BiPredicate, V> filter, Map, V> params, boolean null2IsNull) { return allEq(true, filter, params, null2IsNull); } @@ -77,12 +58,12 @@ public interface MyCompare extends Serializable { * @param null2IsNull 是否参数为 null 自动执行 isNull 方法, false 则忽略这个字段 * @return children */ - Children allEq(boolean condition, BiPredicate, V> filter, Map, V> params, boolean null2IsNull); + Children allEq(boolean condition, BiPredicate, V> filter, Map, V> params, boolean null2IsNull); /** * ignore */ - default Children eq(SFunction column, Object val) { + default Children eq(SFunction column, Object val) { return eq(true, column, val); } @@ -94,12 +75,12 @@ public interface MyCompare extends Serializable { * @param val 值 * @return children */ - Children eq(boolean condition, SFunction column, Object val); + Children eq(boolean condition, SFunction column, Object val); /** * ignore */ - default Children ne(SFunction column, Object val) { + default Children ne(SFunction column, Object val) { return ne(true, column, val); } @@ -111,12 +92,12 @@ public interface MyCompare extends Serializable { * @param val 值 * @return children */ - Children ne(boolean condition, SFunction column, Object val); + Children ne(boolean condition, SFunction column, Object val); /** * ignore */ - default Children gt(SFunction column, Object val) { + default Children gt(SFunction column, Object val) { return gt(true, column, val); } @@ -128,12 +109,12 @@ public interface MyCompare extends Serializable { * @param val 值 * @return children */ - Children gt(boolean condition, SFunction column, Object val); + Children gt(boolean condition, SFunction column, Object val); /** * ignore */ - default Children ge(SFunction column, Object val) { + default Children ge(SFunction column, Object val) { return ge(true, column, val); } @@ -145,12 +126,12 @@ public interface MyCompare extends Serializable { * @param val 值 * @return children */ - Children ge(boolean condition, SFunction column, Object val); + Children ge(boolean condition, SFunction column, Object val); /** * ignore */ - default Children lt(SFunction column, Object val) { + default Children lt(SFunction column, Object val) { return lt(true, column, val); } @@ -162,12 +143,12 @@ public interface MyCompare extends Serializable { * @param val 值 * @return children */ - Children lt(boolean condition, SFunction column, Object val); + Children lt(boolean condition, SFunction column, Object val); /** * ignore */ - default Children le(SFunction column, Object val) { + default Children le(SFunction column, Object val) { return le(true, column, val); } @@ -179,12 +160,12 @@ public interface MyCompare extends Serializable { * @param val 值 * @return children */ - Children le(boolean condition, SFunction column, Object val); + Children le(boolean condition, SFunction column, Object val); /** * ignore */ - default Children between(SFunction column, Object val1, Object val2) { + default Children between(SFunction column, Object val1, Object val2) { return between(true, column, val1, val2); } @@ -197,12 +178,12 @@ public interface MyCompare extends Serializable { * @param val2 值2 * @return children */ - Children between(boolean condition, SFunction column, Object val1, Object val2); + Children between(boolean condition, SFunction column, Object val1, Object val2); /** * ignore */ - default Children notBetween(SFunction column, Object val1, Object val2) { + default Children notBetween(SFunction column, Object val1, Object val2) { return notBetween(true, column, val1, val2); } @@ -215,12 +196,12 @@ public interface MyCompare extends Serializable { * @param val2 值2 * @return children */ - Children notBetween(boolean condition, SFunction column, Object val1, Object val2); + Children notBetween(boolean condition, SFunction column, Object val1, Object val2); /** * ignore */ - default Children like(SFunction column, Object val) { + default Children like(SFunction column, Object val) { return like(true, column, val); } @@ -232,12 +213,12 @@ public interface MyCompare extends Serializable { * @param val 值 * @return children */ - Children like(boolean condition, SFunction column, Object val); + Children like(boolean condition, SFunction column, Object val); /** * ignore */ - default Children notLike(SFunction column, Object val) { + default Children notLike(SFunction column, Object val) { return notLike(true, column, val); } @@ -249,12 +230,12 @@ public interface MyCompare extends Serializable { * @param val 值 * @return children */ - Children notLike(boolean condition, SFunction column, Object val); + Children notLike(boolean condition, SFunction column, Object val); /** * ignore */ - default Children likeLeft(SFunction column, Object val) { + default Children likeLeft(SFunction column, Object val) { return likeLeft(true, column, val); } @@ -266,12 +247,12 @@ public interface MyCompare extends Serializable { * @param val 值 * @return children */ - Children likeLeft(boolean condition, SFunction column, Object val); + Children likeLeft(boolean condition, SFunction column, Object val); /** * ignore */ - default Children likeRight(SFunction column, Object val) { + default Children likeRight(SFunction column, Object val) { return likeRight(true, column, val); } @@ -283,5 +264,5 @@ public interface MyCompare extends Serializable { * @param val 值 * @return children */ - Children likeRight(boolean condition, SFunction column, Object val); + Children likeRight(boolean condition, SFunction column, Object val); } diff --git a/src/main/java/com/github/mybatisplus/wrapper/interfaces/MyFunc.java b/src/main/java/com/github/mybatisplus/wrapper/interfaces/MyFunc.java index ed72cfe..f30dcb3 100644 --- a/src/main/java/com/github/mybatisplus/wrapper/interfaces/MyFunc.java +++ b/src/main/java/com/github/mybatisplus/wrapper/interfaces/MyFunc.java @@ -1,18 +1,3 @@ -/* - * Copyright (c) 2011-2021, baomidou (jobob@qq.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package com.github.mybatisplus.wrapper.interfaces; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; @@ -26,10 +11,7 @@ import java.util.function.Consumer; import static java.util.stream.Collectors.toList; /** - * 查询条件封装 - * - * @author hubin miemie HCL - * @since 2017-05-26 + * copy {@link com.baomidou.mybatisplus.core.conditions.interfaces.Func} */ @SuppressWarnings("unchecked") public interface MyFunc extends Serializable { diff --git a/src/main/java/com/github/mybatisplus/wrapper/interfaces/MyLambdaJoin.java b/src/main/java/com/github/mybatisplus/wrapper/interfaces/MyLambdaJoin.java index fb5140b..94cc1aa 100644 --- a/src/main/java/com/github/mybatisplus/wrapper/interfaces/MyLambdaJoin.java +++ b/src/main/java/com/github/mybatisplus/wrapper/interfaces/MyLambdaJoin.java @@ -3,6 +3,9 @@ package com.github.mybatisplus.wrapper.interfaces; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.github.mybatisplus.toolkit.Constant; +/** + * @author yulichang + */ public interface MyLambdaJoin { default Children leftJoin(Class clazz, SFunction left, SFunction right) { diff --git a/src/main/java/com/github/mybatisplus/wrapper/interfaces/MySFunctionQuery.java b/src/main/java/com/github/mybatisplus/wrapper/interfaces/MySFunctionQuery.java index 42d27f1..7789635 100644 --- a/src/main/java/com/github/mybatisplus/wrapper/interfaces/MySFunctionQuery.java +++ b/src/main/java/com/github/mybatisplus/wrapper/interfaces/MySFunctionQuery.java @@ -1,18 +1,3 @@ -/* - * Copyright (c) 2011-2021, baomidou (jobob@qq.com). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package com.github.mybatisplus.wrapper.interfaces; import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;