post json数据到接口

请求:

 1 curl -X POST "http://localhost:8080/hello2" -H "accept: */*" -H "Content-Type: application/json" -d "{ \"username\": \"test\"}" 

 

接口:

1 @PostMapping("/hello2")
2 public String hello2(@RequestBody Map<String,String> data){
3     System.out.println(data.getClass());
4     return "hello "+data.get("username");
5 }

 

posted @ 2021-12-02 22:45  现在开始JAVA  阅读(71)  评论(0)    收藏  举报