我想让这个方法返回{"valid":true/false}
@ResponseBody
@RequestMapping(value = "/checkUser", method = RequestMethod.POST)
Boolean checkUsersAvailable(@RequestParam("username") String username) {
return contentService.getUser(username) == null;
}
我添加了这些注释:
@JsonGetter("valid")
@JsonProperty("valid")
但它仍无效。
答案 0 :(得分:0)
您无法返回基本类型并获取JSON对象作为响应。 您可以使用包装器或类似的东西:
@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);
}