问题一:0丢失问题,例如前端页面000001,导出的Excel表数据变为1。
JAVA: 这样写的话会导致数值变为字符串,在excel表里数据无法进行计算。
写在ServiceImpl,为需要的表字段添加concat(‘\t’, 字段名);
String columnStr = "concat('\t', 字段1), concat('\t', 字段2), concat('\t', 子段3)"
或者写在.XML,为需要的表字段添加concat(字段名, ' ');
select concat(字段1, '') as 字段1, concat(字段2, '') as 字段2, concat(字段3, '') as 字段3 from 表名
问题二:对于decimal(21,6)的数据进行处理,保留两位小数。
前端: 使用 :formatter = "rounding"
<template>
<div>
<el-table>
<el-table-column :formatter="rounding"></el-table-column>
</el-table>
</div>
</template>
<script>
export default {
methods: {
rounding(row, column,cellValue,index){
let flag = "账户固定牌价" == column.label
if (flag) {
if (!(row[column.property] == null) && cellValue != null) {
return parseFloat(row[column.property]).toFixed(2)
}else {
return row[column.property]
}
} else {
return row[column.property]
}
}
}
}
</script>
后端:为表字段添加round(字段名,保留几位);
问题三:数据导出错位,表字段与对应的数据发生错位。
解决:在导出部分获取表字段使用断点,直接获取正确的数据顺序
System.out.printIn(columnStr), 通过断点获取该值,修改sql语句为对应的数据顺序。
问题四:精度丢失问题,例如数据库中数据为1.020,但是后端输出数据为1.02,前端页面数据为1.02。
第一步:
发现出现这个问题的数据,在数据库的类型是decimal(23,3),而在实体类中,定义该值使用了double或者Long 来定义。将double和Long修改为BigDecimal之后,后端输出变为了1.020。
第二步:发现网上有该问题解决方法(解决前后端传递BigDecimal时发生的精度丢失问题)
解决1:将BigDecimal类型的字段改成String类型。
解决2:在该字段上添加
@JsonSerialize(using= ToStringSerializer.class)
使用了方案2成功解决。