SpringBoot系列-01-Http-Post请求

时间:2021-06-28 18:18:45   收藏:0   阅读:0
//region 1.0 接收 Form 表单数据
/**
* Post:PostMapping 传 Body 参数 form-data
* */
@PostMapping(value = "/book/h11")
public String addHeader(@RequestParam("name") String name,@RequestParam("author") String author) {
return "formdata - | " + name + author ;
}

/**
* Post: PostMapping 传 Body 参数 form-data(隐藏 dynamic)
*/
@PostMapping(value = "/book/post/mapparam")
public String addHeader(@RequestParam Map<String, Object> map) {
return "formdata - | dynamic- " + map.get("name") +"|*|"+ map.get("author") ;
}

/**
* Post: PostMapping 传 Body 参数 form-data(隐藏 dynamic)| 参数是 数组
*/
@PostMapping(value = "/book/post/listparam")
public String addHeader(@RequestParam String[] names) {
return Arrays.toString(names);
}


/**
* Post: PostMapping 传 Body 参数 form-data(隐藏 dynamic)| 参数是 实体类
*/
@PostMapping(value = "/book/post/formdataclass")
public String addHeaderformdata(User useraa) {
return "formdata-class |"+useraa.getAccount();
}
//endregion

//region 2.0 接收 JSON 数据
/**
* 传参数 一个类( Body) --注意 是 RequestMapping
* */
@RequestMapping(method = RequestMethod.POST, value = "/book/h5")
public String addHeader(@RequestBody User useraa) {
return "Post" + useraa.getGener() ;
}
//endregion

//region 3.0 特殊处理的 JSON 数据 RequestMapping 可以直接接收单个参数的【@RequestPostSingleParam 自定义注解类{private}
//@RequestMapping(method = RequestMethod.POST, value = "/book/sd")

@RequestMapping(method = RequestMethod.POST,value = "/book/post/postjson")
public Integer addJsomn(@RequestPostSingleParam Integer id) {
return id ;
}
//endregion
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!