当我不使用时@RequestBody
,会在我的课堂@PathVariable
id
上自动设置。Entity
但如果我使用@RequestBody
它不是。我需要在执行验证之前设置id
of 。为什么它在没有它和没有它的情况下都有效?Entity
GenericValidator
@RequestBody
实体类:
public class Entity {
private String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
//...
}
控制器类:
@Controller
@RequestMapping(value = "/entity")
public class EntityController {
@Autowired
private GenericValidator validator;
@InitBinder
private void initBinder(WebDataBinder binder) {
binder.addValidators(validator);
}
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public @ResponseBody Response update(
@PathVariable String id,
@Valid @RequestBody Entity entity)
{
//...
}
}