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>

 

posted @ 2017-01-13 21:21  铁皮子周  阅读(2143)  评论(0编辑  收藏  举报