Reputation: 169
/**
* @param model
* @param condition
* @param maps
* @return
* @throws Exception
*/
@RequestMapping(value="/encodeGrp")
public String encodeGrp(
HttpServletResponse response,
HttpServletRequest request,
ModelMap model,
Condition condition,
@RequestParam Map<String, Object> maps) throws Exception {
{
List<Encode> result = EncodeRepository.encGrpList(maps);
model.addAttribute("result", result);
model.addAttribute("maps", maps);
model.addAttribute("condition", condition);
model.addAttribute("grpNm2", maps.get("grpNm2"));
}
return "admin/encMng/encode/encodeGrp";
So I have a few questions understanding this Contorller code in Spring
1) In this code,
public String encodeGrp(
HttpServletResponse response,
HttpServletRequest request,
ModelMap model,
Condition condition,
@RequestParam Map<String, Object> maps) throws Exception {
I know they are using "Map" as a parameter for getting/setting data. But what does
ModelMap model,
Condition condition,
mean? Are they using model and condition like "Map"? If so, what is the difference with model,condition and Map?
2) In
model.addAttribute("result", result);
model.addAttribute("maps", maps);
model.addAttribute("condition", condition);
it means they are using "result" to get the data from result in jsp page, correct?
I am so confused here...can someone explain it to me?
Upvotes: 0
Views: 103
Reputation: 280172
I really don't know what that Condition
class is. It's possibly being used as a model attribute.
As for ModelMap
, its javadoc states
Implementation of Map for use when building model data for use with UI tools.
In Spring's MVC implementation, the ModelMap
(and other Model...
classes) serve as the intermediary for storing model elements between the controllers and the views.
Any attributes you store in a ModelMap
will eventually find themselves in HttpServletRequest
attributes, and this before the view is rendered. The purpose here is to add any objects you will need in your view but without having a dependency on the Servlet API.
In this code
model.addAttribute("result", result);
model.addAttribute("maps", maps);
model.addAttribute("condition", condition);
you're adding a number of model attributes so that they are available in a view, possibly a JSP.
Your Map
parameter
@RequestParam Map<String, Object> maps)
is annotated with @RequestParam
which
If the method parameter is Map or MultiValueMap and a parameter name is not specified, then the map parameter is populated with all request parameter names and values.
(ignore the <String, String>
, the same will happen with <String, Object>
). Therefore, for this parameter, all request parameters will be bound to the Map
.
Upvotes: 2