Liferay+Spring Friendly URL mapping

This is a record for what I play friendly url mapping in Liferay

First, we need to do some configuration in liferay-portal.xml, you can check my previous blog for the setting

<portlet>
<portlet-name>SpringBookReceiver</portlet-name>
<icon>/icon.png</icon>
<configuration-action-class>com.book.configuration.ConfigurationActionImpl</configuration-action-class>
<friendly-url-mapper-class>
com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper
</friendly-url-mapper-class>
<friendly-url-mapping>SpringBookReceiver</friendly-url-mapping>
<friendly-url-routes>
com/book/controller/book-friendly-url-routes.xml
</friendly-url-routes>
<instanceable>false</instanceable>
<header-portlet-css>/css/main.css</header-portlet-css>
<header-portal-javascript>http://code.jquery.com/jquery-1.4.3.min.js</header-portal-javascript>
<footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
</portlet>

Second, in the controller package, create book-friendly-url-routes.xml, and set the url route

<?xml version="1.0"?>
<!DOCTYPE routes PUBLIC "-//Liferay//DTD Friendly URL Routes 6.1.0//EN"
"http://www.liferay.com/dtd/liferay-friendly-url-routes_6_1_0.dtd">
<routes>
<route>
<pattern>/add</pattern>
<generated-parameter name="myaction">addBookForm</generated-parameter> //This is the parameter I set in JSP
</route>
<route>
<pattern>/edit/bookId/{bookId:\d+}</pattern>
<generated-parameter name="myaction">editBookForm</generated-parameter>
</route>
<route>
<pattern>/bookList</pattern>
<implicit-parameter name="p_p_lifecycle">0</implicit-parameter> //This is parameter liferay generated for us.
</route>
</routes>


Third, let's take a look at the jsp where we renderURL

<portlet:renderURL var="showAddBookUrl">
<portlet:param name="myaction" value="addBookForm" />
</portlet:renderURL>
<portlet:renderURL var="editBookURL">
<portlet:param name="myaction" value="editBookForm" />
<portlet:param name="bookId" value="${book.id}" />
</portlet:renderURL>
<portlet:renderURL var="homeUrl">
</portlet:renderURL>

Fourth, in the controller class, I use annotation, just show one case:

@RenderMapping(params = "myaction=addBookForm")
public String renderAddFormView() {
return "addBook";
}

The URL for addBook shows like this: 

<a href="http://localhost:8080/web/guest/home/-/SpringBookReceiver/add">Add Book</a>





评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值