Liferay Portlet的动态URL [英] Dynamic URLs for a Liferay Portlet
问题描述
我正在寻找一种开发具有不同URL的动态内容Liferay Portlet的解决方案.我不会在Liferay中创建单独的页面.所有信息都存储在单独的数据库中,并且所有页面都是使用Liferay Portlet生成的.我当前的Liferay版本是6.2 CE.
I am looking for a solution for developing a dynamic content Liferay Portlet with different URLs. I am not going create separate pages in Liferay.All the information are stored in separate database and all pages are generated by using a Liferay Portlet.My current Liferay version is 6.2 CE.
示例网址为
https://localhost/travel/hotel/Lanzarote/Costa Teguise/Hotel Beatriz Costa & Spa
https://localhost/travel/hotel/Lanzarote/Costa Teguise/Club Siroco Apartments
https://localhost/travel/hotel/Lanzarote/Costa Teguise/El Guarapo Apartments
如何在不使用Liferay创建单独页面的情况下实现不同的URL?如果需要使用Liferay API生成动态URL,我需要使用哪些API组件?
How do I implement different URLs with out creating separate pages in Liferay? If I need to use Liferay API for generate dynamic URLs , what are the API components do I need to use?
推荐答案
您可以通过Liferay友好的URL映射获得非常相似的URL:
You can get very similar urls with Liferay friendly url mapping:
https://localhost:8080/{page}/-/hotel/Lanzarote/Costa Teguise/Hotel Beatriz Costa
https://localhost:8080/{page}/-/hotel/Lanzarote/Costa Teguise/Club Siroco Apartments
https://localhost:8080/{page}/-/hotel/Lanzarote/Costa Teguise/El Guarapo Apartments
要使其正常工作,您需要在liferay-portlet.xml
中配置映射:
To make it work, you need to configure the mapping in liferay-portlet.xml
:
<portlet>
<portlet-name>my-hotel-portlet</portlet-name>
<friendly-url-mapper-class>com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper</friendly-url-mapper-class>
<friendly-url-mapping>hotel</friendly-url-mapping>
<friendly-url-routes>friendly-url-routes.xml</friendly-url-routes>
...
</portlet>
/-/
之后紧随其后的网址的hotel
部分由<friendly-url-mapping>hotel</friendly-url-mapping>
值定义.
The hotel
part of the url that comes right after /-/
is defined by <friendly-url-mapping>hotel</friendly-url-mapping>
value.
配置引用friendly-url-routes.xml
中定义的路由.只需定义一个路由即可:
The configuration refers to the routes defined in friendly-url-routes.xml
. Just one route definition is necessary:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE routes PUBLIC "-//Liferay//DTD Friendly URL Routes 6.2.0//EN" "http://www.liferay.com/dtd/liferay-friendly-url-routes_6_2_0.dtd">
<routes>
<route>
<pattern>/{region}/{town}/{hotel}</pattern>
</route>
</routes>
示例Liferay MVCPortlet方法读取参数:
Sample Liferay MVCPortlet method reading the parameters:
@Override
public void doView(RenderRequest renderRequest, RenderResponse renderResponse) {
String region = ParamUtil.getString(renderRequest, "region");
String town = ParamUtil.getString(renderRequest, "town");
String hotel = ParamUtil.getString(renderRequest, "hotel");
...
}
读取参数的示例Spring控制器方法:
Sample Spring controller method reading the parameters:
@RenderMapping
public String renderHotel(@RequestParam String region, @RequestParam String town, @RequestParam String hotel) {
...
return "hotel/view";
}
有关详细内容,请参见 FriendlyURLMapper .
See FriendlyURLMapper for detailed coverage.
这篇关于Liferay Portlet的动态URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!