BAEL-1088 Model, ModelMap and ModelView in Spring MVC (#2590)

* Add files via upload

* Controller methods are written. Test methods are written based on the controller methods and the view is created as an example.
This commit is contained in:
ahmetcetin39
2017-09-12 01:36:49 +03:00
committed by adamd1985
parent 4cba067620
commit 22015c8007
3 changed files with 118 additions and 0 deletions
@@ -0,0 +1,38 @@
package org.baeldung.controller.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
/**
* In this controller, Model, ModelMap and ModelAndView are shown as examples.
* They are all used to pass parameters to JSP pages.
* 04/09/2017
*
* @author Ahmet Cetin
*/
@Controller
public class PassParametersController {
@RequestMapping(value = "/showViewPage", method = RequestMethod.GET)
public String passParametersWithModel(Model model) {
model.addAttribute("message", "Baeldung");
return "viewPage";
}
@RequestMapping(value = "/printViewPage", method = RequestMethod.GET)
public String passParametersWithModelMap(ModelMap map) {
map.addAttribute("welcomeMessage", "welcome");
map.addAttribute("message", "Baeldung");
return "viewPage";
}
@RequestMapping(value = "/goToViewPage", method = RequestMethod.GET)
public ModelAndView passParametersWithModelAndView() {
ModelAndView modelAndView = new ModelAndView("viewPage");
modelAndView.addObject("message", "Baeldung");
return modelAndView;
}
}
@@ -0,0 +1,11 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<div style="padding: 10px; border-radius: 10px; font-size: 30px; text-align: center;">
Web Application. Passed parameter : ${message}
</div>
</body>
</html>