feat: 扩展rest-bean能力,支持提供表格,表格前端支持状态切换

This commit is contained in:
wangyu 2021-03-22 23:43:01 +08:00
parent baa458ae2c
commit 60f66900c2
5 changed files with 74 additions and 2 deletions

View File

@ -1,5 +1,7 @@
package com.flyfish.framework.compiler.core;
import org.apache.commons.lang3.StringUtils;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Map;
@ -26,10 +28,33 @@ class MemoryClassLoader extends URLClassLoader {
return super.findClass(name);
}
classBytes.remove(name);
return defineClass(name, buf, 0, buf.length);
return defineClass(name, buf);
}
public Map<String, byte[]> getClassBytes() {
return classBytes;
}
/**
* 修复获取package为null的问题定义并验证class
*
* @param name 名称
* @param buf 二进制数据
* @return 结果
*/
@SuppressWarnings("all")
private Class<?> defineClass(String name, byte[] buf) {
// 先定义class然后在上下文基础上判断package有效性
Class<?> defined = defineClass(name, buf, 0, buf.length);
synchronized (defined) {
// 补偿定义包防止缺失
if (null == defined.getPackage()) {
// 包名
String packageName = StringUtils.substringBeforeLast(name, ".");
definePackage(packageName, null, null,
null, null, null, null, null);
}
}
return defined;
}
}

View File

@ -0,0 +1,20 @@
package com.flyfish.framework.domain.po;
import com.flyfish.framework.domain.base.Domain;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 在线表单
*/
@Document("online-forms")
@Data
@EqualsAndHashCode(callSuper = true)
public class OnlineForm extends Domain {
// 配置信息
private String form;
}

View File

@ -2,6 +2,7 @@ package com.flyfish.framework.beans.meta;
import com.flyfish.framework.bean.Result;
import com.flyfish.framework.beans.resolver.DynamicRestBeanResolver;
import com.flyfish.framework.domain.base.Vo;
import com.flyfish.framework.utils.StringFormats;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ClassUtils;
@ -42,7 +43,12 @@ public class BeanController {
BeanInfo info = new BeanInfo();
info.setCode(StringFormats.camel2Line(ClassUtils.getShortClassName(clazz)));
if (clazz.isAnnotationPresent(RestBean.class)) {
info.setName(clazz.getAnnotation(RestBean.class).name());
RestBean annotation = clazz.getAnnotation(RestBean.class);
info.setName(annotation.name());
info.setSearch(BeanProperty.from(annotation.queryClass()));
if (!Vo.class.equals(annotation.listViewClass())) {
info.setColumns(BeanProperty.from(annotation.listViewClass()));
}
}
info.setProperties(BeanProperty.from(clazz));
return Result.ok(info);

View File

@ -19,4 +19,10 @@ public class BeanInfo {
// bean的属性们
private List<BeanProperty> properties;
// 表格列属性
private List<BeanProperty> columns;
// 表格查询属性
private List<BeanProperty> search;
}

View File

@ -4,6 +4,7 @@ import com.flyfish.framework.controller.BaseController;
import com.flyfish.framework.controller.SafeController;
import com.flyfish.framework.domain.base.NameLikeQo;
import com.flyfish.framework.domain.base.Qo;
import com.flyfish.framework.domain.base.Vo;
import com.flyfish.framework.repository.DefaultRepository;
import com.flyfish.framework.service.BaseService;
import com.flyfish.framework.service.impl.BaseServiceImpl;
@ -51,6 +52,20 @@ public @interface RestBean {
*/
Class<? extends Qo> queryClass() default NameLikeQo.class;
/**
* 指定列表视图
*
* @return 结果
*/
Class<? extends Vo> listViewClass() default Vo.class;
/**
* 指定详情视图
*
* @return 结果
*/
Class<? extends Vo> viewClass() default Vo.class;
/**
* 仓库的超类默认是default
*