spring mvc 能不能将请求参数绑定到 Controller 属性上

2016-01-12 17:47:55 +08:00
 MonkeyDLuffy

像 struts2 那样
xxxx/toConfirmOrder.do?itemIds=56121201 http 请求

@Controller
public class ConfirmOrderAction {
//绑定到这个属性上
private String itemIds;
public String toConfirmOrder(){}

..get..
..set..

知道可以这样的
@Controller
public class ConfirmOrderAction {
public String toConfirmOrder(@RequestParam String itemIds){}

2465 次点击
所在节点    程序员
12 条回复
MonkeyDLuffy
2016-01-12 17:50:44 +08:00
求解
ixiaohei
2016-01-12 17:50:56 +08:00
springmvc controller 是单例,帮上面去会有并发读问题,而我所知 springmvc 不能这样做
honam
2016-01-12 17:58:11 +08:00
为什么不绑定在方法的参数里面呢。。这不是更好嚒
MonkeyDLuffy
2016-01-12 18:02:43 +08:00
@honam 原本项目是 struts2 的 现在要改成 spring mvc 的 要改很多很多这样的东西 @ixiaohei 单例问题可以配置 scope 成多例的?
ixiaohei
2016-01-12 18:11:35 +08:00
@MonkeyDLuffy 别弄成原型
saximoer
2016-01-12 18:18:48 +08:00
这么做岂不是舍弃了 SPRINGMVC 的优势?
MonkeyDLuffy
2016-01-12 18:29:06 +08:00
@ixiaohei 嗯 真不行就改吧 @saximoer 主要是 struts2 的那些参数 不清楚哪些是哪个方法用的 参数很多
MonkeyDLuffy
2016-01-12 18:30:20 +08:00
原本的想法是把配置改改就行了 现在要动所有的方法了
vikeria
2016-01-12 20:16:57 +08:00
单例加一,
atom
2016-01-13 00:21:49 +08:00
感觉你要的是 @ RequestParam 这个注解
atom
2016-01-13 00:22:21 +08:00
感觉你要的是 @ RequestBody 这个注解,前面打错了
br00k
2016-01-13 08:32:56 +08:00
并发的时候会出问题,除非确定是只读的。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/250207

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX