Servlet.service() for servlet spring threw exception: java.lang.IllegalStateException: Invalid target for Validator
请看看并帮助我解决这个错误,以前我用户登录页面的验证,它工作正常,但现在它无法正常工作.
这是我的代码片段.
调节器
@Controller
public class NewUserRegistration
{
@Autowired
private UserService userService;
@Autowired
private NewUserValidator newUserValidator;
@InitBinder
public void initBinder(WebDataBinder binder)
{
binder.setValidator(newUserValidator);
}
@RequestMapping(value="/newUserAdd",method=RequestMethod.POST)
public String addUser(@modelattribute("user")@Valid User user,BindingResult result,Model model)
{
return "NewUser";
}
}
验证器
@Component
public class NewUserValidator implements Validator
{
@Override
public boolean supports(Class> classz)
{
return NewUserRegistration.class.equals(classz);
}
@Override
public void validate(Object obj,Errors error)
{
//Validation login for fields
}
}
JSP页面
最佳答案
原文链接:https://www.f2er.com/spring/431912.html