带有占位符的URL映射

 

package com.zhangpn.hello;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class Hello {
    @RequestMapping(value="/hello/{id}",method=RequestMethod.GET)
    public String Hello(@PathVariable(value="id") int id) {
        System.out.println("**************hello*******************"+id);
        return "success";
    }
}

http://localhost:8080/SpringMVC/hello/45

id就被赋值为45

 

posted @ 2018-06-19 13:25  呦,可以呦  阅读(429)  评论(0编辑  收藏  举报