spring boot(用postman来测试rest api)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lh87270202/article/details/84587176
前言

我们开发完spring boot rest接口后,需要自测,当然可能通过junit test 来测试service或用restTemplate来测试rest controller方法,但还是和调方的请求方式有差距,这时可以用postman来模拟http请求,是比较方便的

1、 @RequestBody 接收请求参数

一般spring boot后台都用@RequestBody来直接接收一个对象参数,这个注解会把接收到json字符串自动转成我们定义的参数
在postman中,分别用了3个格式的请求如下
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
都报contentType不支持,因为@RequestBody 支持的contentType类型是application/json,所以需要添加header设置参数Content-Type:application/json如图请求成功
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/lh87270202/article/details/84587176