我的问题是我想在我的每一篇博客文章中添加“.html”扩展名。例如,现在我有一篇博客文章网址'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 '
如果有人能提供帮助,我将不胜感激?
最佳答案
我想知道你为什么想要这个。
无论如何,我认为您可以更改 BlogsEntry
的 urlTitle
字段并将 .html
附加到字符串。每当创建或更新博客时,可以使用 service-wrapper-hook 将 .html
附加到 urlTitle
。
或者,您甚至可以使用 ModelListener
(如果 BlogsEntry Hook 存在),通过使用 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");
}
您可以根据需要改进代码,以上只是一个指导方针。
作为旁注,我总是会尝试与客户推理为什么他们想要某些东西,这不仅有助于抵御不良的更改请求,而且还有助于为客户提供替代方案(这是更少的)对像我们这样的开发商征税;-))。在大多数情况下,这有助于更好地了解客户的业务并提供更好的返回。
关于url-rewriting - 向 liferay 上的博客文章页面添加扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14869377/