SpringMVC(七) RequestMapping 路径中带占位符的URL

使用方法:在@RequestMapping("/delete/{id}")中,通过{id}带入pathvariable,然后在方法中,通过@PathVariable("变量名称") Iteger id 的方式引入占位符。

 

控制器代码:

SpringMVC(七) RequestMapping 路径中带占位符的URL
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";
    }
}
SpringMVC(七) RequestMapping 路径中带占位符的URL

视图代码:

<a href="testparam/100">Test PathVariable</a>

SpringMVC(七) RequestMapping 路径中带占位符的URL

上一篇:EMQX Broker性能测试


下一篇:SpringMVC(八) RequestMapping HiddenHttpMethodFilter