Ho il codice che segue in spring:
Non capisco perché ritorna null il nome...Devo instanziare user? Come risolve?codice:@Controller //Nella classe indexController @RequestMapping("/") public class IndexController { private Model SetModel(Model model) { model.addAttribute("attributo1", "Benvenuto nel sito!"); return model; } @GetMapping public String Welcome (Model model) { this.SetModel(model); return "index"; } //INVIO con POST il nome "LEO" @RequestMapping(method = RequestMethod.POST) public String handlePostRequest (User user, Model model) { user.setName("LEO"); return "accesso"; } } @Controller //Nella clase Accedi: @RequestMapping("/accesso") public class Accedi { //RICEVO la richiesta col GET? @RequestMapping(method = RequestMethod.GET) public String handlGetRequest (User user, Model model) { //Perchè da NULL user.getName? System.out.println(user.getName()); return "accesso"; } }

Rispondi quotando