Spring MVC控制器中绑定数据的可能方式
除了@RequestBody和@ModelAttribute之外,还有哪些可能的方法将数据绑定到SpringMVC控制器的方法参数。我可以使用@Valid绑定数据,实现如下代码Spring MVC控制器中绑定数据的可能方式,spring,spring-mvc,spring-3,Spring,Spring Mvc,Spring 3,除了@RequestBody和@ModelAttribute之外,还有哪些可能的方法将数据绑定到SpringMVC控制器的方法参数。我可以使用@Valid绑定数据,实现如下代码 @RequestMapping(value="/person", method = RequestMethod.POST) public String createPerson(@Valid Person person, BindingResult bindingResult){ ... } 如果您正在发布具有
@RequestMapping(value="/person", method = RequestMethod.POST)
public String createPerson(@Valid Person person, BindingResult bindingResult){
...
}
如果您正在发布具有“Person”模型属性的表单的Person模型,您可以执行以下操作:
public View postUser(@ModelAttribute("person") @Valid Person, BindingResult result)
你想干什么?这个问题毫无意义。陈述你的动机,有人可能会提出你没有想到的解决方案。请具体说明。再解释一下你的问题。你所说的“如何调用此控制器”是什么意思。这是一个post方法,因此在您提交页面后将调用它。是的,但没有上述任何批注(@RequestBody,@modeldattribute)?您的控制器方法有效。您可以使用HTML表单或任何HTTP客户端库调用该方法。按照URL获取一些示例代码