最进在开发关于SpringMVC框架的项目时,发现个数据绑定的问题,如果这个实体对象里的字段类型为long、int、double时,客户端就报400语法错误
源代码:
controller:
@RequestMapping("insertReleaseMapIconConfig")
@ResponseBody
public String insertReleaseMapIconConfig(ReleaseMapIconConfig releaseMapIconConfig ){
String result = "ok";
try{
releaseMapIconConfigService.insertMapIconConfig(releaseMapIconConfig);
}catch(Exception e){
e.printStackTrace();
result = "fail";
}
return result;
}
实体类:
public class ReleaseMapIconConfig{
private String id;
private long maxValue;
private long minValue'
private char unit;
private String icon;
以下setter和getter方法省略
}
解决方案:将long 、int、double、char改为Long、Integer、Double、Character包装类型即可
,即:
public class ReleaseMapIconConfig{
private String id;
private Long maxValue;
private Long minValue'
private Character unit;
private String icon;
以下setter和getter方法省略
}