|
1 | | -package org.baeldung.controller; |
2 | | - |
3 | | -import org.baeldung.model.UserDetails; |
4 | | -import org.springframework.stereotype.Controller; |
5 | | -import org.springframework.ui.Model; |
6 | | -import org.springframework.web.bind.annotation.ModelAttribute; |
7 | | -import org.springframework.web.bind.annotation.RequestMapping; |
8 | | -import org.springframework.web.bind.annotation.RequestMethod; |
9 | | - |
10 | | -@Controller |
11 | | -@RequestMapping("/") |
12 | | -public class UserController { |
13 | | - |
14 | | - @RequestMapping(value = "/", method = RequestMethod.GET) |
15 | | - public String showForm(final Model model) { |
16 | | - final UserDetails user = new UserDetails(); |
17 | | - user.setFirstname("John"); |
18 | | - user.setLastname("Roy"); |
19 | | - user.setEmailId("John.Roy@gmail.com"); |
20 | | - model.addAttribute("user", user); |
21 | | - return "index"; |
22 | | - } |
23 | | - |
24 | | - @RequestMapping(value = "/processForm", method = RequestMethod.POST) |
25 | | - public String processForm(@ModelAttribute(value = "user") final UserDetails user, final Model model) { |
26 | | - // Insert userDetails into DB |
27 | | - model.addAttribute("name", user.getFirstname() + " " + user.getLastname()); |
28 | | - return "hello"; |
29 | | - } |
30 | | - |
31 | | -} |
| 1 | +package org.baeldung.web.controller; |
| 2 | + |
| 3 | +import org.baeldung.model.User; |
| 4 | +import org.springframework.stereotype.Controller; |
| 5 | +import org.springframework.ui.Model; |
| 6 | +import org.springframework.web.bind.annotation.ModelAttribute; |
| 7 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 8 | +import org.springframework.web.bind.annotation.RequestMethod; |
| 9 | + |
| 10 | +@Controller |
| 11 | +@RequestMapping("/") |
| 12 | +public class UserController { |
| 13 | + |
| 14 | + @RequestMapping(value = "/", method = RequestMethod.GET) |
| 15 | + public String showForm(final Model model) { |
| 16 | + final User user = new User(); |
| 17 | + user.setFirstname("John"); |
| 18 | + user.setLastname("Roy"); |
| 19 | + user.setEmailId("John.Roy@gmail.com"); |
| 20 | + model.addAttribute("user", user); |
| 21 | + return "index"; |
| 22 | + } |
| 23 | + |
| 24 | + @RequestMapping(value = "/processForm", method = RequestMethod.POST) |
| 25 | + public String processForm(@ModelAttribute(value = "user") final User user, |
| 26 | + final Model model) { |
| 27 | + // Insert User into DB |
| 28 | + model.addAttribute("name", user.getFirstname() + " " + user.getLastname()); |
| 29 | + return "hello"; |
| 30 | + } |
| 31 | + |
| 32 | +} |
0 commit comments