feat(ExcelUtil): 新增“导出实体类的部分属性为Excel”的功能

pull/376/head
lhy 1 year ago
parent 8984ecba86
commit 3708f7978d

@ -172,6 +172,11 @@ public class ExcelUtil<T>
*/
public String[] excludeFields;
/**
*
*/
private String[] showFields;
public ExcelUtil(Class<T> clazz)
{
this.clazz = clazz;
@ -445,6 +450,67 @@ public class ExcelUtil<T>
}
return list;
}
/**
* listexcel
*
* @param response
* @param list
* @param sheetName
* @param title
* @param showFields fieldName
* @return
*/
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName, String title, List<String> showFields)
{
this.showFields = showFields.toArray(new String[0]);
exportExcel(response, list, sheetName, title);
}
/**
* listexcel
*
* @param response
* @param list
* @param sheetName
* @param showFields fieldName
* @return
*/
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName,List<String> showFields)
{
this.showFields = showFields.toArray(new String[0]);
exportExcel(response, list, sheetName, StringUtils.EMPTY);
}
/**
* listexcel
*
* @param response
* @param list
* @param sheetName
* @param title
* @param showFields fieldName
* @return
*/
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName, String title, String[] showFields)
{
this.showFields = showFields;
exportExcel(response, list, sheetName, title);
}
/**
* listexcel
*
* @param response
* @param list
* @param sheetName
* @param showFields fieldName
* @return
*/
public void exportExcel(HttpServletResponse response, List<T> list, String sheetName,String[] showFields)
{
this.showFields = showFields;
exportExcel(response, list, sheetName, StringUtils.EMPTY);
}
/**
* listexcel
@ -1276,7 +1342,7 @@ public class ExcelUtil<T>
*/
public List<Object[]> getFields()
{
List<Object[]> fields = new ArrayList<Object[]>();
List<Object[]> fields = new ArrayList<>();
List<Field> tempFields = new ArrayList<>();
tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields()));
tempFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
@ -1284,6 +1350,7 @@ public class ExcelUtil<T>
{
if (!ArrayUtils.contains(this.excludeFields, field.getName()))
{
if (this.showFields != null && this.showFields.length != 0 && ArrayUtils.contains(this.showFields,field.getName())) {
// 单注解
if (field.isAnnotationPresent(Excel.class))
{
@ -1319,6 +1386,7 @@ public class ExcelUtil<T>
}
}
}
}
return fields;
}

Loading…
Cancel
Save