我有一個場景,我應該使用 POST 請求(而不是預期的“GET”)搜索物件,并將搜索條件作為請求的主體,類似于以下內容:
{
"criteria": {
"value": "BMC_BaseElement",
"identifier": "some value"
}
}
現在假設我需要根據“值”和“識別符號”進行搜索。我是否需要創建一個相應的“標準”POJO 并讓 spring 反序列化它,使用 getter 獲取“值”和“識別符號”然后搜索或者它通常是如何完成的?
uj5u.com熱心網友回復:
您可以為請求正文創建 POJO 模型,或者在這種情況下,您可以執行以下操作:
import com.fasterxml.jackson.databind.node.ObjectNode;
@PostMapping("/search")
public ResponseEntity<List<Object>> search(@RequestBody ObjectNode body) {
String value = body.at("/criteria/value").textValue();
String identifier = body.at("/criteria/identifier").textValue();
return ResponseEntity.ok(List.of());
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/467199.html
