Skip to content

Commit f4ee749

Browse files
authored
Merge pull request eugenp#445 from toubou91/master
Updates for @ModelAttribute example
2 parents 60ae051 + 8159334 commit f4ee749

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎spring-mvc-java/src/main/java/com/baeldung/web/controller/EmployeeController.java‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33
import java.util.HashMap;
44
import java.util.Map;
55

6-
import com.baeldung.model.Employee;
76
import org.springframework.stereotype.Controller;
7+
import org.springframework.ui.Model;
88
import org.springframework.ui.ModelMap;
99
import org.springframework.validation.BindingResult;
10+
import org.springframework.web.bind.annotation.ControllerAdvice;
1011
import org.springframework.web.bind.annotation.ModelAttribute;
1112
import org.springframework.web.bind.annotation.PathVariable;
1213
import org.springframework.web.bind.annotation.RequestMapping;
1314
import org.springframework.web.bind.annotation.RequestMethod;
1415
import org.springframework.web.bind.annotation.ResponseBody;
1516
import org.springframework.web.servlet.ModelAndView;
1617

18+
import com.baeldung.model.Employee;
19+
1720
@Controller
21+
@ControllerAdvice
1822
public class EmployeeController {
1923

2024
Map<Long, Employee> employeeMap = new HashMap<>();
@@ -43,4 +47,9 @@ public String submit(@ModelAttribute("employee") final Employee employee, final
4347
return "employeeView";
4448
}
4549

50+
@ModelAttribute
51+
public void addAttributes(final Model model) {
52+
model.addAttribute("msg", "Welcome to the Netherlands!");
53+
}
54+
4655
}

‎spring-mvc-java/src/main/webapp/WEB-INF/view/employeeView.jsp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<body>
77

88
<h2>Submitted Employee Information</h2>
9+
<h3>${msg}</h3>
910
<table>
1011
<tr>
1112
<td>Name :</td>

0 commit comments

Comments
 (0)