[英]Make object containing map property to querystring for Java @RequestParam
這是我的 class:
@Getter
@Setter
public class Example {
private boolean taxFree;
private String email;
private Map<Enum,String> additionalConstraints;
}
這是我的端點:
@GetMapping(value = "/search", produces = MediaType.APPLICATION_JSON_VALUE)
public TransformedExample<Example> getPurchases(ExampleSearchQueryModel searchModel,
BindingResult result) {
if (result.hasErrors() || searchModel == null) {
LOGGER.error(result.getAllErrors().toString());
return null;
}
return exampleService.findByExampleSearchModel(searchModel);
}
如果我有一個 class 和這樣的端點,我的查詢字符串將如何顯示,以便 spring 可以填充 map 字段“additionalConstraints”?
additionalConstraints.EMAIL=test 或 additionConstraints[EMAIL]=test
總是導致 map 被映射到 null 或 size(0) map。 我該如何正確地做到這一點?
我建議不要使用@PostMapping
,而是使用@GetMapping
,這樣 Spring 可以直接從請求正文中 map object 。
按照這個鏈接
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.