Merge pull request #445 from toubou91/master

Updates for @ModelAttribute example
This commit is contained in:
Alex Theedom 2016-06-10 00:56:45 +03:00 committed by GitHub
commit f4ee749afc
2 changed files with 11 additions and 1 deletions

View File

@ -3,10 +3,11 @@ package com.baeldung.web.controller;
import java.util.HashMap;
import java.util.Map;
import com.baeldung.model.Employee;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@ -14,7 +15,10 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.baeldung.model.Employee;
@Controller
@ControllerAdvice
public class EmployeeController {
Map<Long, Employee> employeeMap = new HashMap<>();
@ -43,4 +47,9 @@ public class EmployeeController {
return "employeeView";
}
@ModelAttribute
public void addAttributes(final Model model) {
model.addAttribute("msg", "Welcome to the Netherlands!");
}
}

View File

@ -6,6 +6,7 @@
<body>
<h2>Submitted Employee Information</h2>
<h3>${msg}</h3>
<table>
<tr>
<td>Name :</td>