@ResponseBody
public Object validate(
@RequestParam("fieldId") String fieldId, @RequestParam("fieldValue") String fieldValue,
@RequestParam(value = "id", required = false) Long id) {
ValidateResponse response = ValidateResponse.newInstance();
if ("username".equals(fieldId)) {
User user = getUserService().findByUsername(fieldValue);
if (user == null || (user.getId().equals(id) && user.getUsername().equals(fieldValue))) {
//如果msg 不为空 将弹出提示框
response.validateSuccess(fieldId, "");
} else {
response.validateFail(fieldId, "用户名已被其他人使用");
}
}
if ("email".equals(fieldId)) {
User user = getUserService().findByEmail(fieldValue);
if (user == null || (user.getId().equals(id) && user.getEmail().equals(fieldValue))) {
//如果msg 不为空 将弹出提示框
response.validateSuccess(fieldId, "");
} else {
response.validateFail(fieldId, "邮箱已被其他人使用");
}
}
if ("mobilePhoneNumber".equals(fieldId)) {
User user = getUserService().findByMobilePhoneNumber(fieldValue);
if (user == null || (user.getId().equals(id) && user.getMobilePhoneNumber().equals(fieldValue))) {
//如果msg 不为空 将弹出提示框
response.validateSuccess(fieldId, "");
} else {
response.validateFail(fieldId, "手机号已被其他人使用");
}
}
return response.result();
}