我从控制器返回false时遇到了一些问题。首先,正常返回true,因为" true"在JSON中没有任何问题,但是当它应该返回false时会显示:
Error parsing JSON: undefined
undefined:
false
这是我的DAO
@Override
public Boolean checkEmail(String email) {
System.out.println(email);
Query query = em.createQuery("SELECT s FROM StudenciEntity s WHERE s.email LIKE :email");
query.setParameter("email", email);
if (query.getResultList().isEmpty()) {
return false;
}
else {
return true;
}
}
这是控制器
@RequestMapping(value = "/email/{email:.+}", method = RequestMethod.GET)
public ResponseEntity<Boolean> checkEmail(@PathVariable String email) {
Boolean checkEmail = istudenciService.checkEmail(email);
if (checkEmail !=null) {
return new ResponseEntity<Boolean>(checkEmail, HttpStatus.OK);
}
else {
return new ResponseEntity<Boolean>(HttpStatus.NOT_FOUND);
}
}
一开始我正在返回Long的电子邮件(1和-1)并且它有效,然后想要将它设为布尔值,所有这一切都发生了。