SpringMVC(七) RequestMapping 路徑中帶占位符的URL
阿新 • • 發佈:2018-12-01
pre path ucc urn com tle toolbar 分享 復制代碼
使用方法:在@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>
SpringMVC(七) RequestMapping 路徑中帶占位符的URL