Spring控制器可以处理这两种请求吗?Spring MVC中的@RequestParam处理可选参数
1) http://localhost:8080/submit/id/ID123432?logout=true
2) http://localhost:8080/submit/id/ID123432?name=sam&password=543432
如果我定义的那种单个控制器:
@RequestMapping (value = "/submit/id/{id}", method = RequestMethod.GET,
produces="text/xml")
public String showLoginWindow(@PathVariable("id") String id,
@RequestParam(value = "logout", required = false) String logout,
@RequestParam("name") String username,
@RequestParam("password") String password,
@ModelAttribute("submitModel") SubmitModel model,
BindingResult errors) throws LoginException {...}
HTTP请求与 “注销” 是不能接受的。
如果我定义了两个控制器分别处理每个请求,Spring会抱怨“已经有'Controller'bean方法...映射”的异常。
当有人将注销,名称和密码都传递给URL时会发生什么?只要阅读文档,它说'!myParam样式表达式表明指定的参数不应该出现在请求中。“必须尝试。 –
它会找到最好的匹配,它可能会尝试使用'handleLogin',否则它会提供一个异常,说明不能找到映射。 –
只需要注意一点:从安全角度来看,注销应该只接受POST请求,所以_should_有2种方法,并且保持URL不变是毫无意义的。 –