package com.yuanchu.mom.common; import cn.hutool.core.util.StrUtil; import com.yuanchu.mom.annotation.ValueTableShow; import io.swagger.annotations.ApiModelProperty; import java.lang.reflect.Field; import java.util.*; /*李林 * 通过注解快速生成table表头*/ public class PrintChina { public static List> printChina(Class tClass) { //将实体类的属性和注释转换成参数 List fieldList = new ArrayList<>(); while (tClass != null){ fieldList.addAll(new ArrayList<>(Arrays.asList(tClass.getDeclaredFields()))); tClass = (Class) tClass.getSuperclass(); } Field[] fields = new Field[fieldList.size()]; fieldList.toArray(fields); ArrayList> list = new ArrayList<>(); for (Field field : fields) { Map soundVo = new HashMap<>(); boolean bool = field.isAnnotationPresent(ApiModelProperty.class); boolean bool2 = field.isAnnotationPresent(ValueTableShow.class); if (bool2) { int order = field.getAnnotation(ValueTableShow.class).value(); String value = field.getAnnotation(ValueTableShow.class).name(); int width = field.getAnnotation(ValueTableShow.class).width(); if (bool){ value = value.isEmpty() ? field.getAnnotation(ApiModelProperty.class).value() : value; } soundVo.put("label", field.getName()); soundVo.put("value", value); if(width>0){ soundVo.put("width", width); } soundVo.put("order", order + ""); if(list.isEmpty()){ list.add(soundVo); }else{ boolean isAdd = false; for (int i = 0; i < list.size(); i++) { Map map = list.get(i); if(order < Integer.parseInt(map.get("order").toString())){ list.add(i, soundVo); isAdd = true; break; } } if (!isAdd) list.add(soundVo); } } } return list; } }