zoukankan      html  css  js  c++  java
  • 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 使用,那么答案也是可以的。

  • 相关阅读:
    wenbao与powershell
    wenbao与windows
    wenbao与msf
    CCF201612-Python题解
    语不惊人死不休
    为人性僻耽佳句(一)
    Pytorch出现 raise NotImplementedError
    CNN卷积
    python字符串切片
    python----numpy(持续更新)
  • 原文地址:https://www.cnblogs.com/Jeely/p/12613657.html
Copyright © 2011-2022 走看看