2013-02-14 63 views
2

我的問題是我想爲每個博客文章添加'.html'擴展名。例如,現在我有一個博客文章url'http://www.indu.com/blog/-/blogs/creating-a-custom-portlet-in-liferay',我想要的是'http://www.indu.com/blog/-/blogs/creating-a-custom-portlet-in-liferay.html'在liferay的博客帖子頁面添加擴展

如果有人能幫忙,我將不勝感激?

+1

像Advaita指出,我很想知道你爲什麼要這樣做?對於在url結尾添加.html絕對沒有影響。 – 2013-02-14 16:02:13

+0

傑羅姆它的客戶要求在所有頁面中都有.html擴展名。 – 2013-02-15 04:36:37

回答

3

我想知道你爲什麼要這樣做。

無論如何,我認爲你可以更改字段BlogsEntry並將.html附加到字符串中。無論何時創建或更新博客,都可以使用服務包裝掛鉤將.html附加到urlTitle

或者你甚至可以用一個ModelListener,如果它存在BlogsEntry鉤用onCreate & onUpdate方法來更新博客的urlTitle

編輯

urlTitle字段存在於BlogsEntry表。

也可以使用Java以下方法訪問此:

BlogsEntry blog = BlogsEntryLocalServiceUtil.getBlogsEntry(90989); // retrieves the blog-entry 

String blogUrlTitle = blog.getUrlTitle(); 

blog.setUrlTitle(blogUrlTitle + ".html"); // this would set the string 

您可以爲blogUrlTitle所以檢查你不用反覆.html附加到字符串:

if (!blogUrlTitle.contains(".html")) { // append only if the title does not contain `.html` 
    blog.setUrlTitle(blogUrlTitle + ".html"); 
} 

您可以按照自己喜歡的方式來優化代碼,以上只是一條指引。作爲一個側面提示,我會一直試圖與客戶端推薦他們爲什麼需要某些東西,這不僅有助於抵禦不良變更請求,還有助於爲客戶提供一種替代方案(這是對像我們這樣的開發人員減免徵稅;-))。在大多數情況下,這有助於更好地瞭解客戶的業務&提供更好的回報。

+0

+1有效解決方案的不錯選擇 – 2013-02-14 16:00:27

+1

感謝您的幫助Advaita,但您能否指導我在哪裏可以找到BlogsEntry的urlTitle字段? – 2013-02-15 04:35:52

+0

@GarthHuff編輯了答案,請看看。 – 2013-02-15 07:14:28

相關問題