mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
优化
This commit is contained in:
parent
82050c7086
commit
5cc0c32004
@ -30,12 +30,11 @@ public interface MPJBaseMethod extends Constants {
|
||||
if (ConfigProperties.subTableLogic) {
|
||||
sqlScript += (NEWLINE + String.format("${%s.subLogicSql}", WRAPPER));
|
||||
}
|
||||
String normalSqlScript = SqlScriptUtils.convertIf(String.format("AND ${%s}", WRAPPER_SQLSEGMENT), String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT, WRAPPER_NONEMPTYOFNORMAL), true);
|
||||
normalSqlScript += NEWLINE;
|
||||
normalSqlScript += SqlScriptUtils.convertIf(String.format(" ${%s}", WRAPPER_SQLSEGMENT), String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT, WRAPPER_EMPTYOFNORMAL), true);
|
||||
sqlScript += normalSqlScript;
|
||||
sqlScript = SqlScriptUtils.convertChoose(String.format("%s != null", WRAPPER), sqlScript, table.getLogicDeleteSql(false, true));
|
||||
sqlScript += SqlScriptUtils.convertIf(String.format("AND ${%s}", WRAPPER_SQLSEGMENT), String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT, WRAPPER_NONEMPTYOFNORMAL), true);
|
||||
sqlScript += NEWLINE;
|
||||
sqlScript = SqlScriptUtils.convertWhere(sqlScript);
|
||||
sqlScript += SqlScriptUtils.convertIf(String.format(" ${%s}", WRAPPER_SQLSEGMENT), String.format("%s != null and %s != '' and %s", WRAPPER_SQLSEGMENT, WRAPPER_SQLSEGMENT, WRAPPER_EMPTYOFNORMAL), true);
|
||||
sqlScript = SqlScriptUtils.convertChoose(String.format("%s != null", WRAPPER), sqlScript, table.getLogicDeleteSql(false, true));
|
||||
return newLine ? NEWLINE + sqlScript : sqlScript;
|
||||
} else {
|
||||
String sqlScript = getAllSqlWhere(table, false, true, WRAPPER_ENTITY_DOT);
|
||||
|
@ -8,7 +8,6 @@ import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.query.interfaces.MPJJoin;
|
||||
import com.github.yulichang.toolkit.Constant;
|
||||
import com.github.yulichang.toolkit.MPJWrappers;
|
||||
@ -64,7 +63,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
/**
|
||||
* 主表逻辑删除
|
||||
*/
|
||||
private boolean logicSql = ConfigProperties.subTableLogic;
|
||||
private boolean logicSql = true;
|
||||
|
||||
|
||||
public MPJQueryWrapper() {
|
||||
|
@ -8,7 +8,6 @@ import com.github.yulichang.test.join.dto.UserDTO;
|
||||
import com.github.yulichang.test.join.entity.AddressDO;
|
||||
import com.github.yulichang.test.join.entity.AreaDO;
|
||||
import com.github.yulichang.test.join.entity.UserDO;
|
||||
import com.github.yulichang.test.join.mapper.AddressMapper;
|
||||
import com.github.yulichang.test.join.mapper.UserMapper;
|
||||
import com.github.yulichang.toolkit.MPJWrappers;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
@ -85,10 +84,10 @@ class LambdaWrapperTest {
|
||||
* 自连接测试
|
||||
*/
|
||||
@Test
|
||||
void testInner() throws Exception {
|
||||
void testInner() {
|
||||
MPJLambdaWrapper<UserDO> wrapper = new MPJLambdaWrapper<UserDO>()
|
||||
.disableSubLogicDel()
|
||||
.disableLogicDel()
|
||||
// .disableSubLogicDel()
|
||||
// .disableLogicDel()
|
||||
.selectAll(UserDO.class)
|
||||
.selectCollection(UserDO.class, UserDO::getChildren)
|
||||
.leftJoin(UserDO.class, UserDO::getPid, UserDO::getId);
|
||||
|
@ -23,8 +23,16 @@ class QueryWrapperTest {
|
||||
*/
|
||||
@Test
|
||||
void test1() {
|
||||
UserDO userDO = userMapper.selectJoinOne(UserDO.class, new MPJQueryWrapper<UserDO>()
|
||||
.selectAll(UserDO.class).last("LIMIT 1"));
|
||||
MPJQueryWrapper<UserDO> last = new MPJQueryWrapper<UserDO>()
|
||||
.disableLogicDel()
|
||||
.selectAll(UserDO.class)
|
||||
.eq("t.id", 1)
|
||||
.last("LIMIT 1");
|
||||
System.out.println(last.getSqlSegment());
|
||||
System.out.println(last.isEmptyOfNormal());
|
||||
System.out.println(last.nonEmptyOfNormal());
|
||||
UserDO userDO = userMapper.selectJoinOne(UserDO.class, last);
|
||||
|
||||
System.out.println(userDO);
|
||||
|
||||
UserDTO dto = userMapper.selectJoinOne(UserDTO.class, new MPJQueryWrapper<UserDO>()
|
||||
|
Loading…
x
Reference in New Issue
Block a user