jeecg中excel导出字段判空处理

mac2022-06-30  26

jeecg中excel导出字段判空处理

 

我们清楚,jeecg 导出 excel 采用的是 easypoi,不知道是否遇到过这种情况:

我们以一个实体属性为例:

@Excel(name="问题分类",dicCode="xx")private java.lang.String mwoQuestionCategory;

Easypoi 在 @Excel 基础注解里提供了 exportConvert 属性:

@Excel(name="问题分类",width=15,dicCode="mwo_question_type",exportConvert=true)private java.lang.String mwoQuestionCategory;get...set...public java.lang.String convertgetMwoQuestionCategory() {   return mwoQuestionCategory == null ? "" : mwoQuestionCategory;}

该方法为新加入的,跟 get set 方法没交叉,书写规则为 convert + 实体 get方法名称。

如上方实例,mwoQuestionCategory,拼接得到的判空方法为:convert + getMwoQuestionCategory = convertgetMwoQuestionCategory()。


有小伙伴提议,为何不直接在实体 get 方法里做三目运算呢。其实那样做会入侵实体对象,改变原本不需要赋值为空串的空值,当然,如果你的实体仅仅是为了提供给导出 Excel 使用,那么答案也是可以的。

转载于:https://www.cnblogs.com/Jeely/p/11309575.html

最新回复(0)