0

I am trying to send 'user' object to another controller but the method rattr.addAttribute("user",user) is giving error as below

Resolved [org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'com.company.models.User' to required type 'java.lang.String'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'com.company.models.User' to required type 'java.lang.String': no matching editors or conversion strategy found]

Code:

public String Register(@Valid @ModelAttribute("user") User user,Errors errors,Model model,HttpServletRequest request, RedirectAttributes rattrs) {

    
    if(errors.hasErrors()) {
        return "user";
    }
    else {
        
        
       // RegisterService.show(user);
        
        xes.export(user);
        request.setAttribute("user", user);
        request.getAttribute("user");
        
        System.out.println(" console prints till here");
        rattrs.addAttribute("user", user);  
        return "redirect:/success";
        
        }
    
}

How can I send user object through redirect to success page?

No Name
  • 51
  • 1
  • 6

1 Answers1

0

Use addFlashAttribute() instead.

For difference see this. https://stackoverflow.com/a/14470824/6572971

Alien
  • 15,141
  • 6
  • 37
  • 57