前端传入后台的数据类型为数组,后端保存数据需要时String,则需要进行数据转换
//检验项目需要做数据类型转换
if(sampleCrForm.getSampleModel().getTestitem().length > 0){
//数组转换String
String testitem = Arrays.toString(sampleCrForm.getSampleModel().getTestitem());
entity.setTestitem(testitem);
}
保存在数据库表的数据如图:
从数据库查询的数据String需要转换成数组
//检验项目数据类型转换
if(entity.getTestitem().length() > 0){
String testItem = entity.getTestitem();
String testItemSub = testItem.substring(1,testItem.length()-1);
String testItemArrary[] = testItemSub.split(",");
sampleModel.setTestitem(testItemArrary);
}