SpringMvc注解@PathVariable

2023年2月4日07:58:27

 

@PathVariable是spring3.0的一个新功能:接收请求路径中占位符的值

 

用法:

        @RequestMapping("/test/{id}/{name}")
        //返回JSON数据
		@ResponseBody
		public String t1(@PathVariable("id")Integer ids,
				@PathVariable("name")String names) {
			return ids+names;
		}

请求的{ }必须和@PathVariable中的value值相同如果ids为id则可以省略value

@RequestMapping("/test/{id}/{name}")
@ResponseBody
public String t1(@PathVariable Integer id,@PathVariable String name) {
			return id+name;
		}

 

  • 作者:suzhou_xj
  • 原文链接:https://blog.csdn.net/suzhou_xj/article/details/104053446
    更新时间:2023年2月4日07:58:27 ,共 379 字。