mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
fix first npe
This commit is contained in:
parent
e92df45f88
commit
45b68607a2
@ -251,7 +251,7 @@ public class MybatisLabel<E, T> implements Label<T> {
|
|||||||
result.setBaseColumn(mybatisLabel.baseColumn);
|
result.setBaseColumn(mybatisLabel.baseColumn);
|
||||||
result.setProperty(i.getColumProperty());
|
result.setProperty(i.getColumProperty());
|
||||||
result.setJavaType(i.getColumnType());
|
result.setJavaType(i.getColumnType());
|
||||||
result.setJdbcType(Objects.isNull(i.getTableFieldInfo()) ? null : i.getTableFieldInfo().getJdbcType());
|
result.setJdbcType(i.getJdbcType());
|
||||||
result.setSelectNormal(i);
|
result.setSelectNormal(i);
|
||||||
return result;
|
return result;
|
||||||
}).collect(Collectors.toList()));
|
}).collect(Collectors.toList()));
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.github.yulichang.wrapper.apt.resultmap;
|
package com.github.yulichang.wrapper.apt.resultmap;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
|
||||||
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.yulichang.apt.BaseColumn;
|
import com.github.yulichang.apt.BaseColumn;
|
||||||
@ -16,7 +15,6 @@ import org.apache.ibatis.type.JdbcType;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* result 标签
|
* result 标签
|
||||||
@ -71,7 +69,7 @@ public class Result implements IResult {
|
|||||||
result.selectNormal = selectCache;
|
result.selectNormal = selectCache;
|
||||||
result.property = selectCache.getColumProperty();
|
result.property = selectCache.getColumProperty();
|
||||||
result.javaType = selectCache.getColumnType();
|
result.javaType = selectCache.getColumnType();
|
||||||
result.jdbcType = Optional.ofNullable(selectCache.getTableFieldInfo()).map(TableFieldInfo::getJdbcType).orElse(null);
|
result.jdbcType = selectCache.getJdbcType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder(boolean isId, BaseColumn<?> baseColumn, SelectCache selectCache) {
|
public Builder(boolean isId, BaseColumn<?> baseColumn, SelectCache selectCache) {
|
||||||
@ -82,7 +80,7 @@ public class Result implements IResult {
|
|||||||
result.selectNormal = selectCache;
|
result.selectNormal = selectCache;
|
||||||
result.property = selectCache.getColumProperty();
|
result.property = selectCache.getColumProperty();
|
||||||
result.javaType = selectCache.getColumnType();
|
result.javaType = selectCache.getColumnType();
|
||||||
result.jdbcType = Optional.ofNullable(selectCache.getTableFieldInfo()).map(TableFieldInfo::getJdbcType).orElse(null);
|
result.jdbcType = selectCache.getJdbcType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder<T> property(SFunction<T, ?> property) {
|
public Builder<T> property(SFunction<T, ?> property) {
|
||||||
@ -102,7 +100,7 @@ public class Result implements IResult {
|
|||||||
result.javaType = normal.getColumnType();
|
result.javaType = normal.getColumnType();
|
||||||
}
|
}
|
||||||
if (Objects.isNull(result.jdbcType)) {
|
if (Objects.isNull(result.jdbcType)) {
|
||||||
result.jdbcType = Objects.isNull(normal.getTableFieldInfo()) ? null : normal.getTableFieldInfo().getJdbcType();
|
result.jdbcType = normal.getJdbcType();
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
package com.github.yulichang.wrapper.interfaces;
|
package com.github.yulichang.wrapper.interfaces;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||||
import com.github.yulichang.toolkit.SqlHelper;
|
import com.github.yulichang.toolkit.SqlHelper;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 链式调用
|
* 链式调用
|
||||||
@ -62,7 +64,7 @@ public interface Chain<T> extends MPJBaseJoin<T> {
|
|||||||
* JoinWrappers.lambda(User.class)<br />
|
* JoinWrappers.lambda(User.class)<br />
|
||||||
*/
|
*/
|
||||||
default T first() {
|
default T first() {
|
||||||
return list().stream().findFirst().orElse(null);
|
return Optional.of(list()).filter(CollectionUtils::isNotEmpty).map(m -> m.get(0)).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,7 +75,7 @@ public interface Chain<T> extends MPJBaseJoin<T> {
|
|||||||
* JoinWrappers.lambda(User.class)<br />
|
* JoinWrappers.lambda(User.class)<br />
|
||||||
*/
|
*/
|
||||||
default <R> R first(Class<R> resultType) {
|
default <R> R first(Class<R> resultType) {
|
||||||
return list(resultType).stream().findFirst().orElse(null);
|
return Optional.of(list(resultType)).filter(CollectionUtils::isNotEmpty).map(m -> m.get(0)).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.github.yulichang.wrapper.segments;
|
package com.github.yulichang.wrapper.segments;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
|
||||||
import com.github.yulichang.apt.BaseColumn;
|
import com.github.yulichang.apt.BaseColumn;
|
||||||
import com.github.yulichang.apt.Column;
|
import com.github.yulichang.apt.Column;
|
||||||
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
||||||
|
import org.apache.ibatis.type.JdbcType;
|
||||||
import org.apache.ibatis.type.TypeHandler;
|
import org.apache.ibatis.type.TypeHandler;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@ -42,7 +42,9 @@ public interface Select extends Serializable {
|
|||||||
|
|
||||||
String getAlias();
|
String getAlias();
|
||||||
|
|
||||||
TableFieldInfo getTableFieldInfo();
|
Class<?> getPropertyType();
|
||||||
|
|
||||||
|
JdbcType getJdbcType();
|
||||||
|
|
||||||
boolean isFunc();
|
boolean isFunc();
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.github.yulichang.wrapper.segments;
|
package com.github.yulichang.wrapper.segments;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
|
||||||
import com.github.yulichang.apt.BaseColumn;
|
import com.github.yulichang.apt.BaseColumn;
|
||||||
import com.github.yulichang.apt.Column;
|
import com.github.yulichang.apt.Column;
|
||||||
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import org.apache.ibatis.type.JdbcType;
|
||||||
import org.apache.ibatis.type.TypeHandler;
|
import org.apache.ibatis.type.TypeHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -194,9 +194,17 @@ public class SelectApt implements Select {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableFieldInfo getTableFieldInfo() {
|
public Class<?> getPropertyType() {
|
||||||
if (cache != null) {
|
if (cache != null) {
|
||||||
return cache.getTableFieldInfo();
|
return cache.getPropertyType();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JdbcType getJdbcType() {
|
||||||
|
if (cache != null) {
|
||||||
|
return cache.getJdbcType();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.github.yulichang.wrapper.segments;
|
package com.github.yulichang.wrapper.segments;
|
||||||
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
|
||||||
import com.github.yulichang.apt.BaseColumn;
|
import com.github.yulichang.apt.BaseColumn;
|
||||||
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.apache.ibatis.type.JdbcType;
|
||||||
import org.apache.ibatis.type.TypeHandler;
|
import org.apache.ibatis.type.TypeHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,7 +43,7 @@ public class SelectLabel implements Select {
|
|||||||
this.baseColumn = baseColumn;
|
this.baseColumn = baseColumn;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SelectLabel(SelectCache cache, Integer index, Class<?> tagClass, String column, boolean hasTableAlias, String tableAlias) {
|
public SelectLabel(SelectCache cache, Integer index, Class<?> tagClass, String column, boolean hasTableAlias, String tableAlias, BaseColumn<?> baseColumn) {
|
||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.tagClass = tagClass;
|
this.tagClass = tagClass;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user