Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Controller
- public class ContactController {
- private static List<Contact> contacts = new ArrayList<>();
- static {
- contacts.add(new Contact("Barack", "Obama", "barack.o@wh.com", "147-852-965"));
- contacts.add(new Contact("George", "Bush", "george.b@wh.com", "785-985-652"));
- contacts.add(new Contact("Bill", "Clinton", "bill.c@wh.com", "236-587-412"));
- contacts.add(new Contact("Ronald", "Reagan", "ronald.r@wh.com", "369-852-452"));
- }
- @RequestMapping(value = "hello", method = RequestMethod.GET)
- public String get(Model model) {
- ContactForm contactForm = new ContactForm();
- contactForm.setContacts(contacts);
- model.addAttribute( "contactForm", contactForm);
- return "add_contact";
- }
- @RequestMapping(value = "/save", method = RequestMethod.POST)
- public String save(@ModelAttribute ContactForm contactForm, Model model) {
- List<Contact> contactList = contactForm.getContacts();
- if(contactList != null && contactList.size() > 0) {
- contacts = contactList;
- }
- return "show_contact";
- }
- }
- @Configuration
- @EnableWebMvc
- @ComponentScan("controller")
- public class WebConfig extends WebMvcConfigurerAdapter {
- @Bean
- public ViewResolver viewResolver() {
- InternalResourceViewResolver resolver
- = new InternalResourceViewResolver();
- resolver.setPrefix("/WEB-INF/jsp/");
- resolver.setSuffix(".jsp");
- return resolver;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement