Witam moim problemem jest zmiana widoku po zalogowaniu na widok głowny poprzez modelAndView.setViewName("redirect:/");
return modelAndView; :
ControllerLogowania
@ResponseBody
@RequestMapping(value ="/login",method = RequestMethod.POST)
public ModelAndView loginPost(@Valid @ModelAttribute("model")LoginViewModel model, final BindingResult result,
final RedirectAttributes redirectAttributes){
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("model",model);
if(aktualnyKlientService.isAuthenticated()){
System.out.println("chuj w dupe");
return new ModelAndView("redirect:/");
}
String zmienna = model.getHaslo();
Klient klient = klientRepository.findByPesel(model.getPesel());
System.out.println(klient);
if (!result.hasErrors()) {
if (klient == null) {
result.reject("error.loginError", "Niepoprawny login lub hasło.");
System.out.println("nie ma takiego kilenta");
} else if (!Szyfrowanie.sprawdzPoporawnoscHasla(model.getHaslo(), klient.getHaslo())) {
result.reject("error.loginError", "Niepoprawne login lub hasło");
System.out.println("hasło sie nie zgadza");
}
}
if (result.hasErrors()) {
modelAndView.setViewName("/unauthorised/login");
return modelAndView;
}
aktualnyKlientService.setKlient(klient);
modelAndView.setViewName("redirect:/");
return modelAndView;
}
HomeController:
@RequestMapping("/")
public ModelAndView home(){
ModelAndView modelAndView = new ModelAndView();
Klient klient = new Klient();
System.out.println("home controller"+klient);
if(aktualnyKlientService.isAuthenticated()) {
modelAndView.setViewName("/authorised/user");
System.out.println("Jest zalogowany - strona home");
} else {
System.out.println("Przekierowanie na logowanie");
return new ModelAndView("redirect:/login");
}
System.out.println("wykonuje sie chuj wie co");
return modelAndView;
}
Po zalogowaniu powinno wrócić do HomeControllera i w ifie wybrac jeżeli użytkownik poprawnie sie zalogował to otwiera widok user jeżeli nie to wraca do logowania.
Jednak podczas przejścia do tego widoku następuje bład:
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed May 16 1830 CEST 2018
There was an unexpected error (type=Internal Server Error, status=500).
Failed to convert value of type 'com.example.bank.bank.models.LoginViewModel' to required type 'java.lang.String'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'com.example.bank.bank.models.LoginViewModel' to required type 'java.lang.String': no matching editors or conversion strategy found