当前位置: 首页 > 编程笔记 >

SpringBoot请求参数接收方式

松越
2023-03-14
本文向大家介绍SpringBoot请求参数接收方式,包括了SpringBoot请求参数接收方式的使用技巧和注意事项,需要的朋友参考一下

application/json接收

/** 
 * 参数不可为空,可为{}
 * userDto中的属性 非必填 
 */
@RequestMapping("/hello5") 
public String hello5(@RequestBody UserDto userDto) { 
  return userDto.getName() + "," \+ userDto.getAge(); 
}

x-www-form-urlencoded、?拼接、form-data接收

@RequestMapping("/hello1") 
public String hello1(@RequestParam("name") String name) { 
  return name; 
} 
 
@RequestMapping("/hello2") 
public UserDto hello2(@RequestHeader("name") String name, @RequestHeader("age") Integer age) { 
  return new UserDto(name, age); 
} 
 
/** 
 * @param name 非必填 
 */
@RequestMapping("/hello3") 
public String hello3(String name) { 
  return name; 
} 
 
/** 
 * userDto中的属性 非必填 
 */
@RequestMapping("/hello4") 
public String hello4(UserDto userDto) { 
  return userDto.getName() + "," \+ userDto.getAge(); 
}

UserDto

public class UserDto { 
 
  private String name; 
 
  private Integer age; 
 
  public String getName() { 
    return name; 
  } 
 
  public void setName(String name) { 
    this.name = name; 
  } 
 
  public Integer getAge() { 
    return age; 
  } 
 
  public void setAge(Integer age) { 
    this.age = age; 
  } 
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持小牛知识库。

 类似资料:
  • 每当页面尝试提交2MB或更大的文件时,都会发生此错误。但是参数在帖子里!我已经检查了Chrome开发工具。有人知道这个错误吗?Springboot 2.0.3。释放

  • 在Laravel 5.1方法是不接收后数据。 这是我的方法,$request不存储通过post发送的数据。 这是我在测试中对它的称呼: 这就是我的评论- 这是我的路线: 我的方法从URL接收$project ectId,这是工作,但请求是空的,没有我发送的数据从$注释-

  • 可以在模板中直接使用$Request对象,直接输入它的属性或调用它的大部分方法,但只支持方法的第一个参数; // 调用Request对象的get方法 传入参数为id {$Request.get.id} // 调用Request对象的param方法 传入参数为name {$Request.param.name} // 调用Request对象的param方法 传入参数为post.post_title

  • 可以在模板中直接使用$Request对象,直接输入它的属性或调用它的大部分方法,但只支持方法的第一个参数; // 调用Request对象的get方法 传入参数为id {$Request.get.id} // 调用Request对象的param方法 传入参数为name {$Request.param.name} // 调用Request对象的param方法 传入参数为post.post_title

  • 本文向大家介绍Struts2之Action接收请求参数和拦截器详解,包括了Struts2之Action接收请求参数和拦截器详解的使用技巧和注意事项,需要的朋友参考一下 技术分析之在Struts2框架中使用Servlet的API 1. 在Action类中也可以获取到Servlet一些常用的API 需求:提供JSP的表单页面的数据,在Action中使用Servlet的API接收到,然后保存到三个域对象

  • 我试图写一个请求从我的服务器获取消息在使用签名,消息看起来像这样, POST/134148934511/Localhost/?Action=ReceiveMessage 但我收到了一条错误消息(尽管我拥有所需的权限)。(我确信aws版本4的签名过程是正确的(通过S3检查))我做错了什么?