Updates for @ModelAttribute example

This commit is contained in:
toubou91 2016-06-09 00:22:06 +02:00
parent 378d0c084b
commit 815933447b
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>