我有许多目的地(比如150+),每个目的地有两个不同的变体:
我为每个变体生成了一个html。例如:
通用格式是:
这些文件中的每一个都被写入/seo/Destination/
如何将给定的URL映射到struts 2中的这些文件:
www.mysite.com/seo/Destinations/NewYork-A.html和www.mysite.com/NewYork-Travel => www.mysite.com/seo/Destinations/NewYork-B.html
通用:
www.mysite.com/seo/Destinations/Destination-A.html www.mysite.com/Destination-Tourism =>
和
www.mysite.com/seo/Destinations/Destination-B.html www.mysite.com/Destination-Travel =>
我可以这样做的一种方法是生成尽可能多的操作(目的* variant_types),然后将每个操作的结果映射到适当的html文件中。就像这样:
<action name="NewYork-Tourism">
<result name="success">/seo//Destination/NewYork-A.html</result>
</action>
<action name="NewYork-Travel">
<result name="success">/seo//Destination/NewYork-B.html</result>
</action>。。诸若此类
还有其他(更好的)方法来做这件事吗?
发布于 2012-08-23 06:39:26
在我看来,一种快速的方法是使用通配符映射,Struts2有一种方法,即通配符,它似乎更适合您。
随着应用程序大小的增加,动作映射的数量也会增加。通配符可用于将类似的映射组合为更多的泛型映射。
就像这样
<action name="List*s" class="actions.List{1}s">
<result>list{1}s.jsp</result>
</action>更多详情请参阅文件。
发布于 2012-08-23 06:47:52
它也可以采用另一种方式,在操作类的公共字符串execute()方法上,您将有嵌套的if else。例如,第一个if语句是针对纽约,用户选择的旅游,您将返回一个值“纽约旅游”。
在我们的struts.xml中
<action name="Destinations" method="execute" class="Your Class Location">
<result name="New-York-Tourism">/seo//Destination/NewYork-Tourism.html</result>
<result name="New-York-Travel">/seo//Destination/NewYork-Travel.html</result>
. . . . . .
https://stackoverflow.com/questions/12085921
复制相似问题