189 8069 5689

springmvc中如何使用@PathVariable实现获取url中的参数

本篇文章给大家分享的是有关springmvc中如何使用@PathVariable实现获取url中的参数,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

创新互联专业为企业提供阜南网站建设、阜南做网站、阜南网站设计、阜南网站制作等企业网站建设、网页设计与制作、阜南企业网站模板建站服务,十载阜南做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

spring mvc中的@PathVariable是用来获得请求url中的动态参数

 @Controller 
public class TestController { 
   @RequestMapping(value="/user/{userId}/roles/{roleId}",method = RequestMethod.GET) 
   public String getLogin(@PathVariable("userId") String userId, 
     @PathVariable("roleId") String roleId){ 
     System.out.println("User Id : " + userId); 
     System.out.println("Role Id : " + roleId); 
     return "hello"; 
   } 
   @RequestMapping(value="/product/{productId}",method = RequestMethod.GET) 
   public String getProduct(@PathVariable("productId") String productId){ 
      System.out.println("Product Id : " + productId); 
      return "hello"; 
   } 
   @RequestMapping(value="/javabeat/{regexp1:[a-z-]+}", 
      method = RequestMethod.GET) 
   public String getRegExp(@PathVariable("regexp1") String regexp1){ 
      System.out.println("URI Part 1 : " + regexp1); 
      return "hello"; 
   } 
} 

以上就是springmvc中如何使用@PathVariable实现获取url中的参数,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联行业资讯频道。


本文题目:springmvc中如何使用@PathVariable实现获取url中的参数
链接URL:http://cdxtjz.cn/article/gghsci.html

其他资讯