This commit is contained in:
yulichang 2021-02-01 02:06:14 +08:00
parent 99890d94dd
commit f5d7aff146
12 changed files with 74 additions and 154 deletions

View File

@ -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;

View File

@ -9,6 +9,7 @@ import java.util.List;
/**
* SQL 注入器
*
* @author yulichang
* @see DefaultSqlInjector
*/
public class MySqlInjector extends DefaultSqlInjector {

View File

@ -30,7 +30,7 @@ public enum SqlMethod {
"<script>\nSELECT %s FROM %s <if test=\"ew.alias != null and ew.alias != ''\">${ew.alias}</if> <if test=\"ew.from != null and ew.from != ''\">${ew.from}</if> %s %s\n</script>"),
SELECT_JOIN_MAPS_PAGE("selectJoinMapsPage", "返回Map集合并分页",
"<script>\nSELECT %s FROM %s <if test=\"ew.from != null and ew.from != ''\">${ew.from}</if> %s %s\n</script>");
"<script>\nSELECT %s FROM %s <if test=\"ew.alias != null and ew.alias != ''\">${ew.alias}</if> <if test=\"ew.from != null and ew.from != ''\">${ew.from}</if> %s %s\n</script>");
private final String method;
private final String desc;

View File

@ -2,6 +2,9 @@ package com.github.mybatisplus.query.interfaces;
import com.github.mybatisplus.toolkit.Constant;
/**
* @author yulichang
*/
public interface MyJoin<Children> {
default Children leftJoin(String joinSql) {

View File

@ -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;
}

View File

@ -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
* <p>统一处理解析 lambda 获取 column</p>
*
* @author hubin miemie HCL
* @since 2017-05-26
* copy {@link com.baomidou.mybatisplus.core.conditions.AbstractLambdaWrapper}
*/
@SuppressWarnings("serial")
public abstract class MyAbstractLambdaWrapper<T, Children extends MyAbstractLambdaWrapper<T, Children>>

View File

@ -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<T, Children extends MyAbstractWrapper<T, Children>> extends MyWrapper<T>

View File

@ -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<T> extends MyAbstractLambdaWrapper<T, MyLambdaQueryWrapper<T>>
@ -57,7 +39,6 @@ public class MyLambdaQueryWrapper<T> extends MyAbstractLambdaWrapper<T, MyLambda
*/
private SharedString from = new SharedString();
/**
* 主表别名
*/
@ -118,7 +99,7 @@ public class MyLambdaQueryWrapper<T> extends MyAbstractLambdaWrapper<T, MyLambda
for (SFunction<S, ?> s : columns) {
Class<S> 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<T> extends MyAbstractLambdaWrapper<T, MyLambda
TableInfo info = TableInfoHelper.getTableInfo(entityClass);
Assert.notNull(info, "table can not be find");
info.getFieldList().stream().filter(predicate).collect(Collectors.toList()).forEach(
i -> selectColumns.add(new SelectColumn(entityClass, info.getTableName(), i.getColumn())));
i -> selectColumns.add(new SelectColumn(entityClass, info.getTableName(), i.getColumn(), null)));
return typedThis;
}
public final <S, X> MyLambdaQueryWrapper<T> selectAs(SFunction<S, ?> columns, SFunction<X, ?> alias) {
Class<S> 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<T> extends MyAbstractLambdaWrapper<T, MyLambda
private String columnName;
private String alias;
public SelectColumn(Class<?> 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<T> extends MyAbstractLambdaWrapper<T, MyLambda
public void setColumnName(String columnName) {
this.columnName = columnName;
}
public String getAlias() {
return alias;
}
public void setAlias(String alias) {
this.alias = alias;
}
}
}

View File

@ -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;
@ -22,11 +7,7 @@ import java.util.Map;
import java.util.function.BiPredicate;
/**
* 查询条件封装
* <p>比较值</p>
*
* @author hubin miemie HCL
* @since 2017-05-26
* {@link com.baomidou.mybatisplus.core.conditions.interfaces.Compare}
*/
public interface MyCompare<Children> extends Serializable {

View File

@ -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<Children> extends Serializable {

View File

@ -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<Children> {
default <T, X> Children leftJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right) {

View File

@ -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;