[英]Spring 3 - What's the standard way of sending @RequestParam values back to the view?
I have a simple controller that handles a submit with a couple of parameters, not so much that I would consider creating a command object to store them.我有一个简单的 controller 处理带有几个参数的提交,而不是我会考虑创建一个命令 object 来存储它们。
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.在我的 controller 中,我使用@RequestParam
注释了参数,但我必须将这些值发送到视图,我不知道最好的方法是什么。
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.如果我有命令 object 我可以使用modelAttribute
html:form
标签上的 modelAttribute 来绑定参数,但我不想为一堆字段创建命令 object。
What is the preferred way of sending the values to the view (request attributes, model attributes... )?将值发送到视图的首选方式是什么(请求属性、model 属性...)?
I'd say model attributes.我会说 model 属性。 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带有JSTL的示例
<html>
...
<c:out value="${q}" />
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.