@WebServlet("必须使用/开头")
@RequestMapping(无须使用/开头) user/login 或者 /user/login
1.精准地址[1个/多个] /user/login {"地址1","地址2"}
2.支持模糊:使用 * 代替一层字符串 | 使用 ** 代替任意层任意字符串
/user/* -> user/a user/aaaa
/user/* -> user user/a user/a/a/a/a/a...
3.类上和方法上添加@RequestMapping的区别
类上提取通用的访问地址
方法上是具体的handler地址
访问:类地址 + 方法地址
4.请求方式制定
客户端 -> http (get|post|put|delete) -> DispatcherServlet -> handler
默认情况: @RequestMapping("/login") 只要地址正确,任意请求方式都可以访问
指定请求方式:
1.指定一种请求方式:@RequestMapping(value = "/register", method = RequestMethod.POST)
2.指定多种请求方式:@RequestMapping(value = "/register", method = {RequestMethod.GET,RequestMethod.POST})
不符合指定请求方式:会出现405异常!!!
5.注解进阶 (只能使用在方法上)
get @GetMapping == @RequestMapping(xxx, RequestMethod=GET)
post @PostMapping == @RequestMapping(xxx, RequestMethod=POST)
put @PutMapping == @RequestMapping(xxx, RequestMethod=PUT)
delete @DeleteMapping == @RequestMapping(xxx, RequestMethod=DELETE)
package com.suchuanlin.requestmapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/user")
public class UserController {
//handler -> 注册到handlerMapping 指定访问地址
/**
* @WebServlet("必须使用/开头")
*
* @RequestMapping(无须使用/开头) user/login 或者 /user/login
*
* 1.精准地址[1个/多个] /user/login {"地址1","地址2"}
*
* 2.支持模糊:使用 * 代替一层字符串 | 使用 ** 代替任意层任意字符串
* /user/* -> user/a user/aaaa
* /user/* -> user user/a user/a/a/a/a/a...
*
* 3.类上和方法上添加@RequestMapping的区别
* 类上提取通用的访问地址
* 方法上是具体的handler地址
* 访问:类地址 + 方法地址
*
* 4.请求方式制定
* 客户端 -> http (get|post|put|delete) -> DispatcherServlet -> handler
* 默认情况: @RequestMapping("/login") 只要地址正确,任意请求方式都可以访问
* 指定请求方式:
* 1.指定一种请求方式:@RequestMapping(value = "/register", method = RequestMethod.POST)
* 2.指定多种请求方式:@RequestMapping(value = "/register", method = {RequestMethod.GET,RequestMethod.POST})
* 不符合指定请求方式:会出现405异常!!!
*
* 5.注解进阶 (只能使用在方法上)
* get @GetMapping == @RequestMapping(xxx, RequestMethod=GET)
* post @PostMapping == @RequestMapping(xxx, RequestMethod=POST)
* put @PutMapping == @RequestMapping(xxx, RequestMethod=PUT)
* delete @DeleteMapping == @RequestMapping(xxx, RequestMethod=DELETE)
*
*/
@RequestMapping // /user
@GetMapping
public String index(){
return null;
}
@RequestMapping(value = "/login", method = RequestMethod.POST) //作用:1.注册地址,2.将handler注册到handlerMapping中
@PostMapping("/login")
public String login(){
return null;
}
@RequestMapping(value = "/register", method = {RequestMethod.GET,RequestMethod.POST})
public String register(){
return null;
}
}