feat:实现缺省的code规则

This commit is contained in:
wangyu 2022-01-06 23:42:17 +08:00
parent f459899a53
commit 04b2152ab7
4 changed files with 22 additions and 1 deletions

View File

@ -4,8 +4,11 @@ import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.util.function.Supplier;
/**
* 框架配置
*
* @author wangyu
*/
@Setter
@ -18,4 +21,6 @@ public class FrameworkConfiguration {
private boolean debug = false;
private boolean shortPassword = false;
private Supplier<String> codeSupplier = null;
}

View File

@ -2,6 +2,8 @@ package com.flyfish.framework.constant;
import com.flyfish.framework.config.FrameworkConfiguration;
import java.util.function.Supplier;
/**
* 框架静态配置
*
@ -25,4 +27,16 @@ public interface Frameworks {
config.setDebug(true);
return config;
}
static FrameworkConfiguration codeSupplier(Supplier<String> codeSupplier) {
config.setCodeSupplier(codeSupplier);
return config;
}
static String getCode() {
if (null != config.getCodeSupplier()) {
return config.getCodeSupplier().get();
}
return null;
}
}

View File

@ -3,6 +3,7 @@ package com.flyfish.framework.domain.base;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.flyfish.framework.annotations.Generation;
import com.flyfish.framework.annotations.Property;
import com.flyfish.framework.constant.Frameworks;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
@ -33,7 +34,7 @@ public abstract class Domain implements Po, Named, Serializable {
@Property(title = "编码", inherited = true)
@NotBlank(message = "编码不可为空")
@Generation(Generation.Strategy.CODE)
protected String code;
protected String code = Frameworks.getCode();
/**
* 名称

View File

@ -11,6 +11,7 @@ import java.util.function.Supplier;
*/
public final class FieldUtils {
public static <T> T complete(T value, Supplier<T> supplier) {
return ObjectUtils.isEmpty(value) ? supplier.get() : value;
}