mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-25 00:00:12 +08:00
优化代码
This commit is contained in:
parent
ef520f3944
commit
dd5003427d
@ -4,6 +4,9 @@ import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||||
import org.apache.ibatis.session.Configuration;
|
import org.apache.ibatis.session.Configuration;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yulichang
|
* @author yulichang
|
||||||
* @since 1.4.3
|
* @since 1.4.3
|
||||||
@ -19,4 +22,6 @@ public interface ITableInfoAdapter {
|
|||||||
boolean mpjHasPK(TableInfo tableInfo);
|
boolean mpjHasPK(TableInfo tableInfo);
|
||||||
|
|
||||||
Configuration mpjGetConfiguration(TableInfo tableInfo);
|
Configuration mpjGetConfiguration(TableInfo tableInfo);
|
||||||
|
|
||||||
|
Field mpjGetField(TableFieldInfo fieldInfo, Supplier<Field> supplier);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,9 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|||||||
import com.github.yulichang.adapter.base.ITableInfoAdapter;
|
import com.github.yulichang.adapter.base.ITableInfoAdapter;
|
||||||
import org.apache.ibatis.session.Configuration;
|
import org.apache.ibatis.session.Configuration;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yulichang
|
* @author yulichang
|
||||||
@ -40,4 +42,9 @@ public class TableInfoAdapterV33x implements ITableInfoAdapter {
|
|||||||
public Configuration mpjGetConfiguration(TableInfo tableInfo) {
|
public Configuration mpjGetConfiguration(TableInfo tableInfo) {
|
||||||
return tableInfo.getConfiguration();
|
return tableInfo.getConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Field mpjGetField(TableFieldInfo fieldInfo, Supplier<Field> supplier) {
|
||||||
|
return supplier.get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,9 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
|||||||
import com.github.yulichang.adapter.base.ITableInfoAdapter;
|
import com.github.yulichang.adapter.base.ITableInfoAdapter;
|
||||||
import org.apache.ibatis.session.Configuration;
|
import org.apache.ibatis.session.Configuration;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yulichang
|
* @author yulichang
|
||||||
* @since 1.4.3
|
* @since 1.4.3
|
||||||
@ -35,4 +38,9 @@ public class TableInfoAdapter implements ITableInfoAdapter {
|
|||||||
public Configuration mpjGetConfiguration(TableInfo tableInfo) {
|
public Configuration mpjGetConfiguration(TableInfo tableInfo) {
|
||||||
return tableInfo.getConfiguration();
|
return tableInfo.getConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Field mpjGetField(TableFieldInfo fieldInfo, Supplier<Field> supplier) {
|
||||||
|
return fieldInfo.getField();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,17 @@ public class UpdateJoin extends MPJAbstractMethod {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String mpjConvertIfEwParam(String param, boolean newLine) {
|
public String mpjConvertIfEwParam(String param, boolean newLine) {
|
||||||
return super.convertIfEwParam(param, newLine);
|
try {
|
||||||
|
return super.convertIfEwParam(param, newLine);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
return convertIfEwParamOverride(param, newLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String convertIfEwParamOverride(final String param, final boolean newLine) {
|
||||||
|
return SqlScriptUtils.convertIf(SqlScriptUtils.unSafeParam(param),
|
||||||
|
String.format("%s != null and %s != null", WRAPPER, param), newLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,6 +3,7 @@ package com.github.yulichang.method;
|
|||||||
import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
||||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
||||||
import org.apache.ibatis.mapping.MappedStatement;
|
import org.apache.ibatis.mapping.MappedStatement;
|
||||||
import org.apache.ibatis.mapping.SqlSource;
|
import org.apache.ibatis.mapping.SqlSource;
|
||||||
|
|
||||||
@ -35,7 +36,17 @@ public class UpdateJoinAndNull extends MPJAbstractMethod {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String mpjConvertIfEwParam(String param, boolean newLine) {
|
public String mpjConvertIfEwParam(String param, boolean newLine) {
|
||||||
return super.convertIfEwParam(param, newLine);
|
try {
|
||||||
|
return super.convertIfEwParam(param, newLine);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
return convertIfEwParamOverride(param, newLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String convertIfEwParamOverride(final String param, final boolean newLine) {
|
||||||
|
return SqlScriptUtils.convertIf(SqlScriptUtils.unSafeParam(param),
|
||||||
|
String.format("%s != null and %s != null", WRAPPER, param), newLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,6 +15,7 @@ import com.github.yulichang.wrapper.interfaces.Update;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -206,7 +207,12 @@ public class UpdateJoinWrapper<T> extends MPJAbstractLambdaWrapper<T, UpdateJoin
|
|||||||
}
|
}
|
||||||
Object val;
|
Object val;
|
||||||
try {
|
try {
|
||||||
val = fieldInfo.getField().get(obj);
|
Field field = AdapterHelper.getTableInfoAdapter().mpjGetField(fieldInfo, () -> {
|
||||||
|
Field field1 = ReflectionKit.getFieldMap(obj.getClass()).get(fieldInfo.getProperty());
|
||||||
|
field1.setAccessible(true);
|
||||||
|
return field1;
|
||||||
|
});
|
||||||
|
val = field.get(obj);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user