SpringBoot请求参数接收方式
更新时间:2020年02月07日 08:33:30 作者:aa东
这篇文章主要介绍了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; } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
相关文章
BeanUtils.copyProperties复制对象结果为空的原因分析
这篇文章主要介绍了BeanUtils.copyProperties复制对象结果为空的原因分析,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2022-06-06
最新评论