diff --git a/flyfish-data/src/main/java/com/flyfish/framework/domain/base/Domain.java b/flyfish-data/src/main/java/com/flyfish/framework/domain/base/Domain.java index 1e4b67e..b4622b9 100644 --- a/flyfish-data/src/main/java/com/flyfish/framework/domain/base/Domain.java +++ b/flyfish-data/src/main/java/com/flyfish/framework/domain/base/Domain.java @@ -9,6 +9,7 @@ import org.springframework.data.annotation.Transient; import org.springframework.data.mongodb.core.index.Indexed; import org.springframework.data.mongodb.core.mapping.Document; +import javax.validation.constraints.NotBlank; import java.io.Serializable; @Document @@ -29,6 +30,7 @@ public abstract class Domain implements Po, Serializable { * 编号 */ @Property(title = "编码", inherited = true) + @NotBlank(message = "编码不可为空") protected String code; /** @@ -36,6 +38,7 @@ public abstract class Domain implements Po, Serializable { */ @Indexed @Property(title = "名称", inherited = true) + @NotBlank(message = "名称不可为空") protected String name; /** diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java index a028216..6403564 100644 --- a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java @@ -1,6 +1,9 @@ package com.flyfish.framework.beans.meta; +import com.alibaba.fastjson.annotation.JSONField; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; import com.flyfish.framework.annotations.Properties; import com.flyfish.framework.annotations.*; import com.flyfish.framework.beans.enums.ValidationCandidate; @@ -10,6 +13,7 @@ import com.flyfish.framework.utils.ReflectionUtils; import com.flyfish.framework.utils.StringFormats; import lombok.Data; import lombok.val; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.ListUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ClassUtils; @@ -54,8 +58,13 @@ public class BeanProperty { private BeanPropertyType type; // 只读属性,不生成于表单 + @JsonIgnore private transient boolean readonly; + // 继承属性,不生成于表单 + @JsonIgnore + private transient boolean inherited; + // 属性 private Map props; @@ -106,6 +115,7 @@ public class BeanProperty { property.setTitle(props.inherited() ? parentName + props.title() : props.title()); property.setDescription(props.description()); property.setReadonly(props.readonly()); + property.setInherited(props.inherited()); property.setGroup(props.group()); // 优雅地设置排序 MergedAnnotation order = annotations.get(Order.class); @@ -277,7 +287,6 @@ public class BeanProperty { .findFirst(); if (found.isPresent()) { BeanProperty property = found.get(); - property.title = prop.title(); if (prop.order() != 0) { property.order = prop.order(); } @@ -288,6 +297,13 @@ public class BeanProperty { if (prop.readonly()) { origin.remove(property); } + // 存在校验,替换名称文案(仅inherit) + if (property.inherited && CollectionUtils.isNotEmpty(property.validation)) { + property.validation.forEach(validation -> validation.setMessage(validation.getMessage() + .replace(property.title, prop.title()))); + } + // 设置标题 + property.title = prop.title(); } else { BeanProperty property = new BeanProperty(); property.setType(BeanPropertyType.STRING);