fix first npe

This commit is contained in:
yulichang 2024-07-30 16:09:21 +08:00
parent e92df45f88
commit 45b68607a2
6 changed files with 25 additions and 15 deletions

View File

@ -251,7 +251,7 @@ public class MybatisLabel<E, T> implements Label<T> {
result.setBaseColumn(mybatisLabel.baseColumn);
result.setProperty(i.getColumProperty());
result.setJavaType(i.getColumnType());
result.setJdbcType(Objects.isNull(i.getTableFieldInfo()) ? null : i.getTableFieldInfo().getJdbcType());
result.setJdbcType(i.getJdbcType());
result.setSelectNormal(i);
return result;
}).collect(Collectors.toList()));

View File

@ -1,6 +1,5 @@
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.support.SFunction;
import com.github.yulichang.apt.BaseColumn;
@ -16,7 +15,6 @@ import org.apache.ibatis.type.JdbcType;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
/**
* result 标签
@ -71,7 +69,7 @@ public class Result implements IResult {
result.selectNormal = selectCache;
result.property = selectCache.getColumProperty();
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) {
@ -82,7 +80,7 @@ public class Result implements IResult {
result.selectNormal = selectCache;
result.property = selectCache.getColumProperty();
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) {
@ -102,7 +100,7 @@ public class Result implements IResult {
result.javaType = normal.getColumnType();
}
if (Objects.isNull(result.jdbcType)) {
result.jdbcType = Objects.isNull(normal.getTableFieldInfo()) ? null : normal.getTableFieldInfo().getJdbcType();
result.jdbcType = normal.getJdbcType();
}
return this;
}

View File

@ -1,10 +1,12 @@
package com.github.yulichang.wrapper.interfaces;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.github.yulichang.interfaces.MPJBaseJoin;
import com.github.yulichang.toolkit.SqlHelper;
import java.util.List;
import java.util.Optional;
/**
* 链式调用
@ -62,7 +64,7 @@ public interface Chain<T> extends MPJBaseJoin<T> {
* JoinWrappers.lambda(User.class)<br />
*/
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 />
*/
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);
}
/**

View File

@ -1,9 +1,9 @@
package com.github.yulichang.wrapper.segments;
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
import com.github.yulichang.apt.BaseColumn;
import com.github.yulichang.apt.Column;
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;
import java.io.Serializable;
@ -42,7 +42,9 @@ public interface Select extends Serializable {
String getAlias();
TableFieldInfo getTableFieldInfo();
Class<?> getPropertyType();
JdbcType getJdbcType();
boolean isFunc();

View File

@ -1,11 +1,11 @@
package com.github.yulichang.wrapper.segments;
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
import com.github.yulichang.apt.BaseColumn;
import com.github.yulichang.apt.Column;
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
import lombok.Getter;
import lombok.Setter;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;
/**
@ -194,9 +194,17 @@ public class SelectApt implements Select {
}
@Override
public TableFieldInfo getTableFieldInfo() {
public Class<?> getPropertyType() {
if (cache != null) {
return cache.getTableFieldInfo();
return cache.getPropertyType();
}
return null;
}
@Override
public JdbcType getJdbcType() {
if (cache != null) {
return cache.getJdbcType();
}
return null;
}

View File

@ -1,10 +1,10 @@
package com.github.yulichang.wrapper.segments;
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
import com.github.yulichang.apt.BaseColumn;
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
import lombok.Getter;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;
/**
@ -43,7 +43,7 @@ public class SelectLabel implements Select {
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.index = index;
this.tagClass = tagClass;