,我有以下功能在我的抽象控制器覆蓋通用控制器
public abstract class GenericController<T extends PersistentObject> {
...
...
...
@RequestMapping(value = "/validation.json", method = RequestMethod.POST)
@ResponseBody
public ValidationResponse ajaxValidation(@Valid T t, BindingResult result) {
ValidationResponse res = new ValidationResponse();
if (!result.hasErrors()) {
res.setStatus("SUCCESS");
} else {
res.setStatus("FAIL");
List<FieldError> allErrors = result.getFieldErrors();
List<ErrorMessage> errorMesages = new ArrayList<ErrorMessage>();
for (FieldError objectError : allErrors) {
errorMesages.add(new ErrorMessage(objectError.getField(),
objectError.getDefaultMessage()));
}
res.setErrorMessageList(errorMesages);
}
return res;
}
在大多數情況下,驗證是足夠的不同類型的實體。現在,我想自定義驗證我的具體控制器上,因爲
@Controller
@RequestMapping("user")
public class UserController extends GenericController<User> {
@RequestMapping(value = "/validation.json", method = RequestMethod.POST)
@ResponseBody
public ValidationResponse ajaxValidation(@Valid User user,
BindingResult result, Locale locale) {
ValidationResponse res = super.ajaxValidation(user, result);
if (!user.getPassword().equals(user.getConfirmPassword())) {
res.setStatus("FAIL");
res.getErrorMessageList().add(
new ErrorMessage("confirmPassword", messageSource
.getMessage("password.mismatch", null, locale)));
}
return res;
}
}
有了這個,我得到以下錯誤java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'userController' bean method
。我該如何解決這個問題?有更好的方法嗎?
感謝您指出差異,我完全錯過了這一點。 – abiieez