SpringBoot中如何实现请求参数的接收方式?

2026-05-28 10:331阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计220个文字,预计阅读时间需要1分钟。

SpringBoot中如何实现请求参数的接收方式?

json接收JSON数据,参数不为空,可为{,非必填属性,/hello5public String hello5(@RequestBody UserDto userDto){ return userDto.getName() + , + userDto.getAge();}

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; } }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。

本文共计220个文字,预计阅读时间需要1分钟。

SpringBoot中如何实现请求参数的接收方式?

json接收JSON数据,参数不为空,可为{,非必填属性,/hello5public String hello5(@RequestBody UserDto userDto){ return userDto.getName() + , + userDto.getAge();}

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; } }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。