SpringMVC中的@RequestMapping注解中的@PathVariable注解

版权声明:如需转载、粘贴内容,必须在转载和粘贴文中标明文章内容出至 https://blog.csdn.net/ynzcxx/article/details/77198220

先看代码,代码如下:

package com.yoni.springmvc.handlers;  
  
import org.springframework.stereotype.Controller;  
import org.springframework.web.bind.annotation.RequestMapping;  
  
@Controller  
public class HelloWorld {  
      
    @RequestMapping("/helloworld/{id}")  
    public String hello(@PathVariable("id")  int id){  
        System.out.println("Hello World:" + id);
        return "success";  
    }  
      
}  

这是页面的请求代码:
<a href= "helloworld/221" >Hello World</a>

这是提交出去请求,将会在控制台显示

Hello World:221

猜你喜欢

转载自blog.csdn.net/ynzcxx/article/details/77198220