1. 程式人生 > >SpringMVC(七) RequestMapping 路徑中帶占位符的URL

SpringMVC(七) RequestMapping 路徑中帶占位符的URL

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