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;
}
@Valid
@NotEmpty(message = "不能为空",groups=IVisitor.class)
private List<SalesOrderDetailEntity> entry;
参考页:http://langmnm.iteye.com/blog/2078439