前端的checkbox复选框,传递到后端为数组,数组无法直接存到数据库
①通过fastJson,将数组转换成String存到数据库
②可以遍历数组,通过“,”拼接成字符串,存到数据库
演示:
实体类
public class ProblemCheckRecording implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private String bSealed;
//用于接收数组数组,在数据表中并不存在
@TableField(exist = false)
@JsonProperty(value ="problemCheckbox")
private String[] Checkbox;
}
controller
@ApiOperation("update:修改")
@PostMapping("/update")
@Transactional
public Result update(@RequestBody CheckRecording entity)
{ Result result = new Result();
try {
if(StringUtils.isNotEmpty(entity.getCheckbox()))
{ entity.setBSealed(JSONObject.toJSONString(entity.getCheckbox())); }
baseService.update(entity,plfUser);
}catch (Exception e){
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//手动回滚
return result.error(Result.CODE_ADD_FAILED + ":" + e.getMessage());
}
return result;
}
数据库表中数据