简体   繁体   English

@JsonGetter不起作用

[英]@JsonGetter doesn't work

I want to make this method return {"valid":true/false} 我想让此方法返回{"valid":true/false}

@ResponseBody
@RequestMapping(value = "/checkUser", method = RequestMethod.POST)
Boolean checkUsersAvailable(@RequestParam("username") String username) {
    return contentService.getUser(username) == null;
}

I add these annotations: 我添加以下注释:

@JsonGetter("valid")
@JsonProperty("valid")

But it's still not working. 但是它仍然无法正常工作。

You can't return a primitive type and get JSON object as a response. 您无法返回原始类型并获取JSON对象作为响应。 You can use a wrapper or something like that: 您可以使用包装器或类似方法:

@ResponseBody
@RequestMapping(value = "/checkUser", method = RequestMethod.POST)
Map<String, Boolean> checkUsersAvailable(@RequestParam("username") String username) {
    boolean result = contentService.getUser(username) == null;
    return Collections.singletonMap("success", result);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM