SpringMVC---RequestMapping_PathVariable注解

一:@PathVariable映射URL绑定的占位符

  1. 带占位符的URL是Spring3.0的新增功能,该功能在SpringMVC向REST目标挺进发展过程中具有里程碑的意义。
  2. 通过@PathVariable可以将URL中占位符参数绑定到控制器处理方法的入参中:URL中的{XXX}占位符可以通过@PathVariable(XXX)绑定到操作方法的入参中。

二:实现代码

package com.dhx.handler;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import jdk.nashorn.internal.ir.RuntimeNode.Request;


@RequestMapping("spring")
@Controller
public class SpringTest {
	
	private final String SUCCESS="success";
	
	//@PathVariable 映射URL中的占位符到目标方法的入参中
	@RequestMapping("/testPathVariable/{id}")
	public String testPathVariable(@PathVariable("id") Integer id ) {
		System.out.println("testPathVariable "+ id);
		return SUCCESS;
	}

}
发布了64 篇原创文章 · 获赞 12 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_39093474/article/details/103570159