2013-04-06 19 views
4

我一直在学习使用过去几天的struts2 rest插件。但没有 - 我发现如何映射长期的其他网址。如何在struts2中映射长REST网址 - 使用struts2 rest插件

例如, 如果我要地图像下面的网址:

/profiles/user-test/orders/64/item/4 

其中

username is user-test 
order id is 64 
item id is 4 

我怎样才能像这样映射到一个Struts2的行动?

我在互联网上找到的所有东西只是被编辑/显示的一个单独的等级。但是如果我想在多个层次上显示某些东西 - 那么该如何继续?请指导。

回答

5

你可以用Advanced Wildcard Mappings做到这一点,而REST插件:

/profiles/user-test/orders/64/item/4

用户名是用户测试

订单ID是64

项目ID为4

The这个例子需要的动作配置是:

<action name="/profiles/{username}/orders/{order}/item/{item}" class="fooBarAction"> 
    <result>fooBar.jsp</result> 
</action> 
+0

谢谢,似乎是答案。将尝试。 – 2013-04-08 09:31:58

+1

它的工作!..对于迟到的答复抱歉,我有大学考试。 – 2013-05-21 04:03:16

+0

虽然它不能直接工作,但我不得不使用正则表达式来阻止用户名在配置文件/之后跨越完整的url。与此类似,我将regex与其他{named}变量一起使用。 – 2013-05-21 04:09:43