Updates for @ModelAttribute example
This commit is contained in:
parent
378d0c084b
commit
815933447b
|
@ -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!");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<body>
|
||||
|
||||
<h2>Submitted Employee Information</h2>
|
||||
<h3>${msg}</h3>
|
||||
<table>
|
||||
<tr>
|
||||
<td>Name :</td>
|
||||
|
|
Loading…
Reference in New Issue