数据传递-------@PathVariable

package com.wh.handler;
/**
 * 通过@PathVariable可以绑定占位符参数到方法参数中,例如
 * @PathVariable("userId") Long userId
 */
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/{userid}")
public class TestPathVariable {
	/**
	 * @PathVariable("userid") String uname
	 * 表示将URL中占位符为userid绑定给方法参数中的uname这个变量名
	 */
	@RequestMapping("/hello.action")
	public String h1(@PathVariable("userid") String uname){
		//绑定{xxx}占位符的URL
		System.out.println("userid   "+uname);
		return "sus.jsp";
	}
	
	/**
	 * @PathVariable String userid
	 * 表示将URL中占位符为userid绑定给方法参数中的userid这个变量名
	 * 与第一个的区别:第一个给@PathVariable指定是哪个占位符,第二个是根据参数名来指定是哪个占位符
	 */
	@RequestMapping("/hello2.action")
	public String h2(@PathVariable String userid){
		//绑定{xxx}占位符的URL
		System.out.println("userid2   "+userid);
		return "sus.jsp";
	}
}

 

userid2   pathvariable 

原文地址:https://www.cnblogs.com/1020182600HENG/p/6911470.html