ng mvc + @Valid + @RequestBody 接收json同時校驗javaBean的數據有效性
@Valid @RequestBody CustomerDto customerBean
@RequestMapping(value="/customerDataSync.do",method=RequestMethod.POST)
public BaseResultMessage customerDataSync(@Valid @RequestBody CustomerDto customerBean, BindingResult errorResult) {
logger.info("==> 客戶數據同步:接收到參數:"+customerBean.toString());
BaseResultMessage rm = new BaseResultMessage();
Map<String,Object> errorMap = ValidatorUtils.fieldValidate(errorResult);
String er ="";
if(errorMap!=null) {
for(String key:errorMap.keySet()) {
er = errorMap.get(key)+",";
}
rm.setType(false);
rm.setMsg(er);
logger.error("==>"+rm.toString());
return rm;
}
rm = customerService.updateCustomerData(customerBean);
logger.info("==> 客戶數據同步:返回數據:"+rm.toString());
return rm;
}
參考頁:http://langmnm.iteye.com/blog/2078439
ng mvc + @Valid + @RequestBody 接收json同時校驗javaBean的數據有效性