开发者

Spring 3 - What's the standard way of sending @RequestParam values back to the view?

开发者 https://www.devze.com 2023-03-13 11:54 出处:网络
I have a simple controller that handles a submit with a couple of parameters, not so much that I wo开发者_如何转开发uld consider creating a command object to store them.

I have a simple controller that handles a submit with a couple of parameters, not so much that I wo开发者_如何转开发uld consider creating a command object to store them.

In my controller I have annotated the parameters with @RequestParam but I have to send these values to the view and I don't know what's the best way of doing it.

If I had a command object I could use the modelAttribute on the html:form tag to bind the parameters but I don't want to create a command object for just a bunch of fields.

What is the preferred way of sending the values to the view (request attributes, model attributes ... )?


I'd say model attributes. Something like

@RequestMapping("/path")
public void test(@RequestParam("q") String q, ModelMap model) {
    model.put("q", q);
}

On front end you could print it using your favourite approach. A sample with JSTL

<html> 
   ...
   <c:out value="${q}" />
 </html>
0

精彩评论

暂无评论...
验证码 换一张
取 消