@RequestBody和@RequestParam区别

阅读数:159 评论数:0

跳转到新版页面

分类

python/Java

正文

一、@RequestParam

这个注解可以接收来自http请求体或请求url的QueryString(GET、POST)。它可以接收简单类型的属性,也可以接收对象类型。

@RequestParam有三个配置参数:

(1)required表示是否必须,默认为true,必须。

(2)defaultValue设置请求参数的默认值。

(3)value为接收url的参数名(相当于key值)

@RequestParam用来处理Content-Type为application/x-www-form-urlencoded和form-data编码的内容。

http的Content-Type默认为application/x-www-form-urlencoded。

二、@RequestBody

一般用来处理非Content-Type:application/x-www-form-urlencoded编码格式的数据,比如:application/json、application/xml等类型的数据。

它接收的参数来自于请求体,所以不适用于GET请求。




相关推荐

一、概述 springboot中有两种方式使用kafka时,直接使用kafka-client连接kafka服务;另一种是使用spring-kafka框架来连接kafka。 1、版本兼容 使用时要注意版

当然可以自己写redis的工具类,或者使用第三方开源jar包或代码,这里使用spring boot的集成类。 一、pom依赖 <dependency> <gro

websocket协议基于tcp的网络协议,它实现浏览器与器全双工通信。 spring boot2 +websocket 1、添加依赖 <pre clas

背景: 之前用spring boot+mybatis+oracle,现在要改成spring boot_mybatis+postgresql。 为了想让一套代码即可

共同点 都是用来表示Spring某个类是否可以接收HTTP请求。 不同点 @Controller标识一个spring类是Spring MVC c

系统异常捕获 参见:spring boot 2 全局异常处理 @ControllerAdvice(annotations = {RestController.class}) public class

从SSH(Structs/Spring/Hibernate)到SSM(SpringMVC/Spring/MyBatis),到现在一个S(Spring)就够的年代,可见Spring越来越重要了。<

@ConditionalOnMissingBean只能在@Bean注解的方法上使用。 可以给该注解传入参数例如@ConditionOnMissingBean(name = "exa

2.4版本之前 在之前,我们在yaml配置文件中,使用spring.profiles来定义不同环境的标识,比如下面这样: <pre class="language-ma

在SpringBoot框架中,我们使用最多的是Tomcat,这是SpringBoot默认的容器技术,而且是内嵌式的Tomcat。   同时,SpringBoot也支持Undertow容器,Undert