@RequestParam与@PathVariable的区别

@PathVariable绑定URI模板变量值

@RequestParam直接获取参数

虽然get/post都能用,但是前者多用于get数据少

 @RequestMapping(value = "/{id}/queryOauthInfo", method = RequestMethod.GET)
    public R queryOauthInfo(@PathVariable Long id) {

后者get的数据多

 @RequestMapping(value ="/list", method = RequestMethod.GET)
    public R list(@RequestParam Map<String, Object> params){

ps.

@RequestParam注解主要有哪些参数:

value:参数名字,即入参的请求参数名字,如username表示请求的参数区中的名字为username的参数的值将传入;

required:是否必须,默认是true,表示请求中一定要有相应的参数,否则将报404错误码;

defaultValue:默认值,表示如果请求中没有同名参数时的默认值

原文地址:https://www.cnblogs.com/ydymz/p/8464921.html

时间: 2024-07-31 07:01:00

@RequestParam与@PathVariable的区别的相关文章

@RequestParam和@PathVariable的区别和使用

请求路径上的区别:很明显一个是      ?键值对,一个是  /参数   ,区别很明显 @RequestParam用于获取参数,可获取?username="sss"这种?后面的参数值 如:访问路径为:http://localhost:7012/billing/pay/paySerial?paySerialId=20190821155435120115620216832 @GetMapping("/paySerial") // @RequestMapping(valu

springMVC的注解@RequestParam与@PathVariable的区别

1.在SpringMVC后台控制层获取参数的方式主要有两种, 一种是request.getParameter("name"),另外一种是用注解@RequestParam直接获取. 这里主要讲这个注解 @RequestParam 接下来我们看一下@RequestParam注解主要有哪些参数: value:参数名字,即入参的请求参数名字,如username表示请求的参数区中的名字为username的参数的值将传入: required:是否必须,默认是true,表示请求中一定要有相应的参数,

springMVC中的注解@RequestParam与@PathVariable的区别

@PathVariable绑定URI模板变量值 @PathVariable是用来获得请求url中的动态参数的 @PathVariable用于将请求URL中的模板变量映射到功能处理方法的参数上.//配置url和方法的一个关系@RequestMapping("item/{itemId}") /* @RequestMapping 来映射请求,也就是通过它来指定控制器可以处理哪些URL请求,类似于struts的action请求* @responsebody表示该方法的返回结果直接写入HTTP

【转】@RequestParam @RequestBody @PathVariable 等参数绑定注解详解

@RequestParam @RequestBody @PathVariable 等参数绑定注解详解 2014-06-02 11:24 23683人阅读 评论(2) 收藏 举报 目录(?)[+] 引言: 接上一篇文章,对@RequestMapping进行地址映射讲解之后,该篇主要讲解request 数据到handler method 参数数据的绑定所用到的注解和什么情形下使用: 简介: handler method 参数绑定常用的注解,我们根据他们处理的Request的不同内容部分分为四类:(主

@RequestParam @RequestBody @PathVariable 等参数绑定注解详解(转)

简介: handler method 参数绑定常用的注解,我们根据他们处理的Request的不同内容部分分为四类:(主要讲解常用类型) A.处理requet uri 部分(这里指uri template中variable,不含queryString部分)的注解:   @PathVariable; B.处理request header部分的注解:   @RequestHeader, @CookieValue; C.处理request body部分的注解:@RequestParam,  @Reque

@RequestParam @RequestBody @PathVariable 等参数绑定注解详解

引言: 接上一篇文章,对@RequestMapping进行地址映射讲解之后,该篇主要讲解request 数据到handler method 参数数据的绑定所用到的注解和什么情形下使用: 简介: handler method 参数绑定常用的注解,我们根据他们处理的Request的不同内容部分分为四类:(主要讲解常用类型) A.处理requet uri 部分(这里指uri template中variable,不含queryString部分)的注解:   @PathVariable; B.处理requ

springmvc @RequestParam @RequestBody @PathVariable 等参数绑定注解详解

简介: handler method 参数绑定常用的注解,我们根据他们处理的Request的不同内容部分分为四类:(主要讲解常用类型) A.处理requet uri 部分(这里指uri template中variable,不含queryString部分)的注解:   @PathVariable; B.处理request header部分的注解:   @RequestHeader, @CookieValue; C.处理request body部分的注解:@RequestParam,  @Reque

(转)@RequestParam @RequestBody @PathVariable 等参数绑定注解详解

引言: 接上一篇文章,对@RequestMapping进行地址映射讲解之后,该篇主要讲解request 数据到handler method 参数数据的绑定所用到的注解和什么情形下使用: 简介: handler method 参数绑定常用的注解,我们根据他们处理的Request的不同内容部分分为四类:(主要讲解常用类型) A.处理requet uri 部分(这里指uri template中variable,不含queryString部分)的注解:   @PathVariable; B.处理requ

java - spring mvc 之传参@RequestParam @RequestBody @Pathvariable @RequestHeader注解

1. @PathVariable 当使用@RequestMapping URI template 样式映射时, 即 someUrl/{paramId}, 这时的paramId可通过 @Pathvariable注解绑定它传过来的值到方法的参数上. 示例代码: @Controller @RequestMapping("/owners/{ownerId}") public class RelativePathUriTemplateController { @RequestMapping(&q