sách gpt4 ai đã đi

Springboot trả về responseentity trả về JSON

In lại 作者:行者123 更新时间:2023-11-29 08:28:11 28 4
mua khóa gpt4 Nike

我想在下面返回 JSON。

{ "name": "jackie" }

postman 给我错误。说明

Unexpected 'n'

这里是 Spring Boot 的新手。 1日龄。有没有正确的方法来做到这一点?

   // POST method here
@RequestMapping(method = RequestMethod.POST , produces = "application/json")
ResponseEntity addTopic(@RequestBody Topic topic) {

if (Util.save(topicRepository, new Topic(topic.getTopicName(), topic.getQuestionCount())) != null) {
return Util.createResponseEntity("Name : jackie", HttpStatus.CREATED);
}
return Util.createResponseEntity("Error creating resource", HttpStatus.BAD_REQUEST);
}

1 Câu trả lời

这是我用的:

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<>> hello() {
thử {
Map body = new HashMap<>();
body.put("message", "Hello world");
return new ResponseEntity<>(body, HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}

关于java - springboot 返回 responseentity 返回 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50654291/

28 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com