私の問題は、すべてのブログ投稿に「.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 '
誰でも助けていただければ幸いです。
私の問題は、すべてのブログ投稿に「.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 '
誰でも助けていただければ幸いです。
なぜこれが欲しいのだろうか。
urlTitle
とにかく、フィールドを変更して文字列BlogsEntry
に追加できると思います.html
。ブログが作成または更新されるたびに、service-wrapper-hook を使用.html
してに追加できます。urlTitle
またはModelListener
、BlogsEntry フックが存在する場合は、&メソッドurlTitle
を使用してブログを更新することもできます。onCreate
onUpdate
編集
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");
}
必要に応じてコードを調整できます。上記は単なるガイドラインです。
補足として、私は常にクライアントが何かを望む理由を説明しようとします。これは、悪い変更要求をかわすだけでなく、クライアントに代替案を提供するのにも役立ちます (私たちのような開発者;-) )。ほとんどの場合、これはクライアントのビジネスをよりよく理解し、より良いリターンを提供するのに役立ちます。