SpringMvc路径参数和url的两种实现方式

我们经常采用的SpringMvc路径参数经常的操作是在url后面采用?参数名=值1&参数名2=值2这种方式实现

RequestMapping的作用:

    1)当作用在controller时,我们通过前端用户请求的url找到具体的处理器也就是特定的controller

     2)当作用在method方法上时,映射到对应的具体实现上

  Springmvc在实现路径请求参数实现上有两种方式。

   方式一. http://localhost:8080/page?name=zhangsan&age=23

@RequestMapping(value="page",method=RequestMethod.GET)
public User getUser(String name,int age){
   
    ......

    return   user;
}

  方式二、http://localhost:8080/page/zhangsan/23

@RequestMapping(value="/page/{name}/{age}",RequestMethod.GET)
public User getUser(@PathVariable("name") String name,@PathVariable("age") age){
     
    .....
   return user;
}

 

    

 

posted @ 2018-07-29 14:09  liuwd  阅读(14054)  评论(1编辑  收藏  举报