import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import com.zte.springbootdemo.model.User; @RestController @RequestMapping(value = "/matchUrlController") public class MatchUrlController { //1、全匹配 @RequestMapping(value = "getUserByAll",method = RequestMethod.GET) @ResponseBody ResponseEntity<User> getUserByAll(){ final User user = new User(); user.setId("0"); user.setName("wang"); user.setPhoneNumber("152xxxxxx"); return new ResponseEntity<>(user, HttpStatus.OK); } /*2 * ?:表示匹配任意一个字符,可以放在任意位置,任意数量 * 示例:1、/?/getUserByUrl1-->http://127.0.0.1:8080/matchUrlController/1/getUserByUrl1 * 2、/??getUserByUrl1-->http://127.0.0.1:8080/matchUrlController/xxgetUserByUrl1 * */ @RequestMapping(value = "/?/getUserByUrl1") @ResponseBody ResponseEntity<User> getUserByUrl1(){ final User user = new User(); user.setId("1"); user.setName("wang"); user.setPhoneNumber("152xxxxxx"); return new ResponseEntity<>(user, HttpStatus.OK); } /*3 * *:表示匹配任意数量的字符,包含0个 * 示例:1、/※/getUserByUrl2-->http://127.0.0.1:8080/matchUrlController/1/getUserByUrl2,此时中间至少一个值 * 2、/※getUserByUrl2-->http://127.0.0.1:8080/matchUrlController/123456getUserByUrl2 * */ @RequestMapping(value = "/*getUserByUrl2") @ResponseBody ResponseEntity<User> getUserByUrl2(){ final User user = new User(); user.setId("2"); user.setName("wang"); user.setPhoneNumber("152xxxxxx"); return new ResponseEntity<>(user, HttpStatus.OK); } /*4 * *:表示匹配任意数量的目录,包含0个 * 示例:1、/※※/getUserByUrl2-->http://127.0.0.1:8080/matchUrlController/1/2/getUserByUrl3, * */ @RequestMapping(value = "/**/getUserByUrl3") @ResponseBody ResponseEntity<User> getUserByUrl3(){ final User user = new User(); user.setId("2"); user.setName("wang"); user.setPhoneNumber("152xxxxxx"); return new ResponseEntity<>(user, HttpStatus.OK); } }
@RequestMapping的URL匹配过程
最新推荐文章于 2023-08-04 16:23:19 发布