- @RequestMapping(value="/login",method=RequestMethod.GET)
- public String login(HttpServletRequest request,HttpServletResponse response){
- String strName=request.getParameter("txtName");
- String strPassword=request.getParameter("pwd");
- String sResult="loginError";
-
- if(StringUtils.isBlank(strName)&&StringUtils.isBlank(strPassword)){
- sResult="loginOK";
- }
@RequestMapping(value="/login",method=RequestMethod.GET)
public String login(HttpServletRequest request,HttpServletResponse response){
String strName=request.getParameter("txtName");
String strPassword=request.getParameter("pwd");
String sResult="loginError";
if(StringUtils.isBlank(strName)&&StringUtils.isBlank(strPassword)){
sResult="loginOK";
}
浏览器报错为:
type Status report
message Request method 'POST' not supported
description The specified HTTP method is not allowed for the requested resource.
查network,请求体说明:
因此在建立映射时,应当注意http请求方法与requestMapping注解一致,或者在注解中不再指定method,而是默认通过枚举自动映射所有http请求方法
- public enum RequestMethod {
-
- GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE
-
- }
public enum RequestMethod {
GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE
}
- RequestMethod[] method() default {};
RequestMethod[] method() default {};