我们假设我有一个这种格式的网址action.htm?key0 = value0& key1 = value1。我把它绑定到一个控制器。现在,使用@PathVariable如何绑定key0和key1?例如:
@RequestMapping(value = "/action", params="myParam=myValue")
public String action(@PathVariable String key0, @PathVariable String key1, Model model) {
不起作用。我可以看到的所有示例都是针对休息样式绑定,找不到键值类型的任何内容。
答案 0 :(得分:2)
使用RequestParam注释,例如:
public String create(@Valid Message message, BindingResult bindingResult, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer size) {
很多例子都使用了值=""在RequestParam注释中,例如:
@RequestParam(value = "size", required = false) Integer size
但是,如果没有提供任何值,它将使用参数名称,因此,我认为这是重复,所以不要使用值=""属性。
答案 1 :(得分:1)
为了安息,请执行以下操作:
@RequestMapping(value = "/{key0}/{key1}", method = RequestMethod.GET)
public String action(@PathVariable String key0, @PathVariable String key1)