栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

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

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

spring mvc中的@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"; 
   } 
} 

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持考高分网!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/147781.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号