1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > 超简单实现导出excel时 把数据库字段状态为数字转换成汉字

超简单实现导出excel时 把数据库字段状态为数字转换成汉字

时间:2022-03-06 21:35:49

相关推荐

超简单实现导出excel时 把数据库字段状态为数字转换成汉字

1.写个工具类

public class StatusConverter implements Converter<Integer> {@Overridepublic Class supportJavaTypeKey() {return Integer.class;}@Overridepublic CellDataTypeEnum supportExcelTypeKey() {return CellDataTypeEnum.STRING;}@Overridepublic Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {return cellData.getStringValue().equals("有效") ? 1 : 0;}@Overridepublic CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {return new CellData(value == 1 ? "有效" : "无效");}}

2.在导出对应表单里面的字段上面打注解

@ExcelProperty(value = "有效性", index = 4,converter = StatusConverter.class)private Integer validflag;主要是后面的 converter = StatusConverter.class

以上就可以了

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。