问题概要:对象属性定义为int类型,利用@RequestBody自动转换成对象,从前端传递了一个空串""时,对象属性被转换成了0。
原因:不知。
具体如下:
前端传递的数据为
{alertLevelId: ""}
后端
DTO
public class AlertQueryInDTO extends BaseAuditDTO {
int alertLevelId = -1;
public int getAlertLevelId() { return alertLevelId; } public void setAlertLevelId(int alertLevelId) { this.alertLevelId = alertLevelId; } public void setAlertLevelId(String alertLevelId) { if(CommonUtils.notNullAndEmpty(alertLevelId)) this.alertLevelId = Integer.parseInt(alertLevelId); }
......
}
Resource
public ResponseDTO<List<AlertInfoDTO>> queryAlertInformations(@RequestBody AlertQueryInDTO alertDTO) { 断点 .....
}
进入断点的时候,发现alertLevelId是0,不知道原因.