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


使用方法:在@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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM