mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
update
This commit is contained in:
parent
99890d94dd
commit
f5d7aff146
@ -2,7 +2,6 @@ package com.github.mybatisplus.base;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.github.mybatisplus.wrapper.MyLambdaQueryWrapper;
|
|
||||||
import com.github.mybatisplus.wrapper.MyWrapper;
|
import com.github.mybatisplus.wrapper.MyWrapper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -9,6 +9,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* SQL 注入器
|
* SQL 注入器
|
||||||
*
|
*
|
||||||
|
* @author yulichang
|
||||||
* @see DefaultSqlInjector
|
* @see DefaultSqlInjector
|
||||||
*/
|
*/
|
||||||
public class MySqlInjector extends DefaultSqlInjector {
|
public class MySqlInjector extends DefaultSqlInjector {
|
||||||
|
@ -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>"),
|
"<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集合并分页",
|
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 method;
|
||||||
private final String desc;
|
private final String desc;
|
||||||
|
@ -2,6 +2,9 @@ package com.github.mybatisplus.query.interfaces;
|
|||||||
|
|
||||||
import com.github.mybatisplus.toolkit.Constant;
|
import com.github.mybatisplus.toolkit.Constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yulichang
|
||||||
|
*/
|
||||||
public interface MyJoin<Children> {
|
public interface MyJoin<Children> {
|
||||||
|
|
||||||
default Children leftJoin(String joinSql) {
|
default Children leftJoin(String joinSql) {
|
||||||
|
@ -11,6 +11,8 @@ public interface Constant {
|
|||||||
*/
|
*/
|
||||||
String TABLE_ALIAS = "t";
|
String TABLE_ALIAS = "t";
|
||||||
|
|
||||||
|
String AS = " AS ";
|
||||||
|
|
||||||
String ON = " ON ";
|
String ON = " ON ";
|
||||||
|
|
||||||
String EQUALS = " = ";
|
String EQUALS = " = ";
|
||||||
@ -39,4 +41,5 @@ public interface Constant {
|
|||||||
* " INNER JOIN "
|
* " INNER JOIN "
|
||||||
*/
|
*/
|
||||||
String INNER_JOIN = StringPool.SPACE + INNER + StringPool.SPACE + JOIN + StringPool.SPACE;
|
String INNER_JOIN = StringPool.SPACE + INNER + StringPool.SPACE + JOIN + StringPool.SPACE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
package com.github.mybatisplus.wrapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||||
@ -33,11 +18,7 @@ import java.util.Map;
|
|||||||
import static java.util.stream.Collectors.joining;
|
import static java.util.stream.Collectors.joining;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lambda 语法使用 Wrapper
|
* copy {@link com.baomidou.mybatisplus.core.conditions.AbstractLambdaWrapper}
|
||||||
* <p>统一处理解析 lambda 获取 column</p>
|
|
||||||
*
|
|
||||||
* @author hubin miemie HCL
|
|
||||||
* @since 2017-05-26
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public abstract class MyAbstractLambdaWrapper<T, Children extends MyAbstractLambdaWrapper<T, Children>>
|
public abstract class MyAbstractLambdaWrapper<T, Children extends MyAbstractLambdaWrapper<T, Children>>
|
||||||
|
@ -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;
|
package com.github.mybatisplus.wrapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.ISqlSegment;
|
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;
|
import static java.util.stream.Collectors.joining;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询条件封装
|
* copy {@link com.baomidou.mybatisplus.core.conditions.AbstractWrapper}
|
||||||
*
|
|
||||||
* @author hubin miemie HCL
|
|
||||||
* @since 2017-05-26
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"serial", "unchecked"})
|
@SuppressWarnings({"serial", "unchecked"})
|
||||||
public abstract class MyAbstractWrapper<T, Children extends MyAbstractWrapper<T, Children>> extends MyWrapper<T>
|
public abstract class MyAbstractWrapper<T, Children extends MyAbstractWrapper<T, Children>> extends MyWrapper<T>
|
||||||
|
@ -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;
|
package com.github.mybatisplus.wrapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.SharedString;
|
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.StringPool;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
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.Constant;
|
||||||
import com.github.mybatisplus.toolkit.MyLambdaUtils;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -38,10 +23,7 @@ import java.util.function.Predicate;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lambda 语法使用 Wrapper
|
* copy {@link com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper}
|
||||||
*
|
|
||||||
* @author hubin miemie HCL
|
|
||||||
* @since 2017-05-26
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class MyLambdaQueryWrapper<T> extends MyAbstractLambdaWrapper<T, MyLambdaQueryWrapper<T>>
|
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();
|
private SharedString from = new SharedString();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主表别名
|
* 主表别名
|
||||||
*/
|
*/
|
||||||
@ -118,7 +99,7 @@ public class MyLambdaQueryWrapper<T> extends MyAbstractLambdaWrapper<T, MyLambda
|
|||||||
for (SFunction<S, ?> s : columns) {
|
for (SFunction<S, ?> s : columns) {
|
||||||
Class<S> clazz = MyLambdaUtils.getEntityClass(s);
|
Class<S> clazz = MyLambdaUtils.getEntityClass(s);
|
||||||
TableInfo info = TableInfoHelper.getTableInfo(clazz);
|
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;
|
return typedThis;
|
||||||
@ -129,15 +110,25 @@ public class MyLambdaQueryWrapper<T> extends MyAbstractLambdaWrapper<T, MyLambda
|
|||||||
TableInfo info = TableInfoHelper.getTableInfo(entityClass);
|
TableInfo info = TableInfoHelper.getTableInfo(entityClass);
|
||||||
Assert.notNull(info, "table can not be find");
|
Assert.notNull(info, "table can not be find");
|
||||||
info.getFieldList().stream().filter(predicate).collect(Collectors.toList()).forEach(
|
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;
|
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
|
@Override
|
||||||
public String getSqlSelect() {
|
public String getSqlSelect() {
|
||||||
if (StringUtils.isBlank(sqlSelect.getStringValue())) {
|
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);
|
sqlSelect.setStringValue(s);
|
||||||
}
|
}
|
||||||
return sqlSelect.getStringValue();
|
return sqlSelect.getStringValue();
|
||||||
@ -198,14 +189,15 @@ public class MyLambdaQueryWrapper<T> extends MyAbstractLambdaWrapper<T, MyLambda
|
|||||||
|
|
||||||
private String columnName;
|
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.clazz = clazz;
|
||||||
this.tableName = tableName;
|
this.tableName = tableName;
|
||||||
this.columnName = columnName;
|
this.columnName = columnName;
|
||||||
|
this.alias = alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Class<?> getClazz() {
|
public Class<?> getClazz() {
|
||||||
return clazz;
|
return clazz;
|
||||||
}
|
}
|
||||||
@ -229,5 +221,13 @@ public class MyLambdaQueryWrapper<T> extends MyAbstractLambdaWrapper<T, MyLambda
|
|||||||
public void setColumnName(String columnName) {
|
public void setColumnName(String columnName) {
|
||||||
this.columnName = columnName;
|
this.columnName = columnName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getAlias() {
|
||||||
|
return alias;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlias(String alias) {
|
||||||
|
this.alias = alias;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
package com.github.mybatisplus.wrapper.interfaces;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||||
@ -22,11 +7,7 @@ import java.util.Map;
|
|||||||
import java.util.function.BiPredicate;
|
import java.util.function.BiPredicate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询条件封装
|
* {@link com.baomidou.mybatisplus.core.conditions.interfaces.Compare}
|
||||||
* <p>比较值</p>
|
|
||||||
*
|
|
||||||
* @author hubin miemie HCL
|
|
||||||
* @since 2017-05-26
|
|
||||||
*/
|
*/
|
||||||
public interface MyCompare<Children> extends Serializable {
|
public interface MyCompare<Children> extends Serializable {
|
||||||
|
|
||||||
|
@ -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;
|
package com.github.mybatisplus.wrapper.interfaces;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||||
@ -26,10 +11,7 @@ import java.util.function.Consumer;
|
|||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询条件封装
|
* copy {@link com.baomidou.mybatisplus.core.conditions.interfaces.Func}
|
||||||
*
|
|
||||||
* @author hubin miemie HCL
|
|
||||||
* @since 2017-05-26
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public interface MyFunc<Children> extends Serializable {
|
public interface MyFunc<Children> extends Serializable {
|
||||||
|
@ -3,6 +3,9 @@ package com.github.mybatisplus.wrapper.interfaces;
|
|||||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||||
import com.github.mybatisplus.toolkit.Constant;
|
import com.github.mybatisplus.toolkit.Constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yulichang
|
||||||
|
*/
|
||||||
public interface MyLambdaJoin<Children> {
|
public interface MyLambdaJoin<Children> {
|
||||||
|
|
||||||
default <T, X> Children leftJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right) {
|
default <T, X> Children leftJoin(Class<T> clazz, SFunction<T, ?> left, SFunction<X, ?> right) {
|
||||||
|
@ -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;
|
package com.github.mybatisplus.wrapper.interfaces;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user