@RequestParam和@RequestBody的区别

@RequestBody是用来接收

application/json需要解析json字符串,然后通过json获取参数,这里用到是fastjson
public CommonReturnType login(@RequestBody String jsonStr)  {
        JSONObject requestJson = JSON.parseObject(jsonStr);
        String telphone=(String)requestJson.get("telphone");
        String password=(String)requestJson.get("password");
}

@RequestParam是用来接收

  application/x-www-form-urlencoded  可直接获取参数
public CommonReturnType login(@RequestParam(name="telphone") String telphone,@RequestParam(name="password") String password)  {
        System.out.println(telphone+password)
}


原文地址:https://www.cnblogs.com/llcMite/p/11392790.html

时间: 2024-08-30 16:40:38

@RequestParam和@RequestBody的区别的相关文章

post传参params与body的区别(@RequestParam和@RequestBody的区别)

1.axios post请求  Content-Type默认为 application/x-www-form-urlencoded,我们传递参数的时,params里面的参数(简单的对象,通过 "{}" 或者 "new Object" 创建的)会被以&拼接的方式拼接到请求地址的后面,data里面的参数(简单的对象,通过 "{}" 或者 "new Object" 创建的)会以Form Data的形式存在,但是Form Da

spring boot的@RequestParam和@RequestBody的区别

尊重原创:https://blog.csdn.net/u013306545/article/details/79071683 一.问题描述 由于项目是前后端分离,因此后台使用的是spring boot,做成微服务,只暴露接口.接口设计风格为restful的风格,在get请求下,后台接收参数的注解为RequestBody时会报错:在post请求下,后台接收参数的注解为RequestParam时也会报错. 二.问题原因 由于spring的RequestParam注解接收的参数是来自于requestH

灵活运用的@RequestParam和@RequestBody

最近在编写项目的过程中,老出现前后端传递参数格式不一致.不统一的问题,对于一个已经快工作一年的Java程序员来说,实属不合格,所以我就下来好好研究了一下@RequestParam和@RequestBody的区别,避免大家遭遇同等错误: 一 @RequestParam注解 @Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface RequestParam { /*

@RequestParam、@RequestBody和@ModelAttribute区别

一.@RequestParamGET和POST请求传的参数会自动转换赋值到@RequestParam 所注解的变量上1. @RequestParam(org.springframework.web.bind.annotation.RequestParam)用于将指定的请求参数赋值给方法中的形参.例:(1) get请求: url请求:http://localhost:8080/WxProgram/findAllBookByTag?tagId=1&pageIndex=3 userTest.jsp &l

@RequestParam,@PathVariable和@RequestBody三者区别

@RequestParam注解 顾名思义:获取参数,即是获取传送过来的参数:例如获取下面链接的id参数值: //链接(注意链接格式区别) http://localhost:8090/hello?id=2 //使用@RequestParam注解获取id public String Demo1(@RequestParam String id){ System.out.println("链接中请求参数的id:"+id); return null; } 此时@RequestParam的作用就可

@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与@PathVariable的区别

@PathVariable绑定URI模板变量值 @RequestParam直接获取参数 虽然get/post都能用,但是前者多用于get数据少 @RequestMapping(value = "/{id}/queryOauthInfo", method = RequestMethod.GET) public R queryOauthInfo(@PathVariable Long id) { 后者get的数据多 @RequestMapping(value ="/list&quo