Browse Source

Merge pull request #713 from TangDH03/master

导出时,忽略Model中的static final和transient
pull/729/head
Jiaju Zhuang 5 years ago committed by GitHub
parent
commit
254dfc0e3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java
  2. 2
      src/test/java/com/alibaba/easyexcel/test/demo/write/ComplexHeadData.java
  3. 2
      src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java

9
src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java

@ -1,6 +1,7 @@
package com.alibaba.excel.metadata.property;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@ -123,6 +124,14 @@ public class ExcelHeadProperty {
Map<Integer, Field> customFiledMap = new TreeMap<Integer, Field>();
for (Field field : fieldList) {
ExcelIgnore excelIgnore = field.getAnnotation(ExcelIgnore.class);
if(Modifier.isStatic(field.getModifiers())&&Modifier.isFinal(field.getModifiers())){
ignoreMap.put(field.getName(),field);
continue;
}
if(Modifier.isTransient(field.getModifiers())){
ignoreMap.put(field.getName(),field);
continue;
}
if (excelIgnore != null) {
ignoreMap.put(field.getName(), field);
continue;

2
src/test/java/com/alibaba/easyexcel/test/demo/write/ComplexHeadData.java

@ -13,6 +13,8 @@ import lombok.Data;
**/
@Data
public class ComplexHeadData {
private final static String TITLE = "title";
private transient String trans = "transient";
@ExcelProperty({"主标题", "字符串标题"})
private String string;
@ExcelProperty({"主标题", "日期标题"})

2
src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java

@ -85,7 +85,7 @@ public class WriteTest {
* <p>
* 2. 使用{@link ExcelProperty}注解指定复杂的头
* <p>
* 3. 直接写即可
* 3. 直接写即可,写入时会忽略static final和 transient
*/
@Test
public void complexHeadWrite() {

Loading…
Cancel
Save