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>