使用resttemplate java发送json obj

2ic8powd  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(286)

因此,我尝试使用http请求发送json obj,它不会在终端上显示任何错误,但数据从未被第三方接收,下面是我使用方法post的代码

@RequestMapping(value = "/unicornsByEntity", method = RequestMethod.POST,
        consumes = MediaType.APPLICATION_JSON_VALUE,
        produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Booking> Booking(@RequestBody JSONObject jobj) throws RestClientException, JsonProcessingException {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<String> entity = new HttpEntity<String>(jobj.toString(), headers);
    return restTemplate.postForEntity(
            "http://localhost:8080/hotel/Booking",
            entity,
            Booking.class);
}

这是第三方中的代码或Map

@RequestMapping(value = "/Booking", method = RequestMethod.POST)
public ResponseEntity<?> insertStudent(@RequestBody JSONObject jobj) throws IOException, ParseException {
       JSONObject book = hotelrepo.bookDetail(jobj);
        return (new ResponseEntity<>(book, HttpStatus.CREATED));
}

这是postman中的json对象

{
"Booking":{
    "name":"Jansen Stanlie",
    "hotel name":"Aryaduta",
    "Room":{
            "Type":"suite",
            "Quantity":3
    }
}

}假设它会将值返回给 Postman ,但永远不会返回任何值。这里是它工作时的值

{
"Message": "Please Complete your payment using your booking id",
"Booking Status": "Success",
"Booking Details": {
    "Booking_id": "DeZd2jgS",
    "Hotel Name": "Aryaduta",
    "harga": 2150000,
    "name": "Jansen Stanlie",
    "Tanggal Pesanan": "Thu Jul 08 00:06:08 ICT 2021",
    "Room": {
        "Room type": "suite",
        "Quantity": 3
    }
}

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题