使用方法:在@RequestMapping("/delete/{id}")中,通过{id}带入pathvariable,然后在方法中,通过@PathVariable("变量名称") Iteger id 的方式引入占位符。
控制器代码:
package com.tiekui.springmvc.handlers; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class TestPathVariable { @RequestMapping("/testparam/{id}") public String test(@PathVariable("id") Integer id){ System.out.println(id); return "success"; } }
视图代码:
<a href="testparam/100">Test PathVariable</a>