【发布时间】:2020-01-30 20:39:11
【问题描述】:
我的 URL 有一些参数,所以我使用友好的 URL 来解决 Liferays 默认生成的丑陋 URL。
这几个参数有时是空的,这意味着它不需要,但其他时候给我一些我用于查询的 ID。
示例参数不是null:
https://myliferay.com/example-portlet/-/example-portlet/search/idTable-7
//it works
例如null参数:
https://myliferay.com/example-portlet/-/example-portlet/search/idTable-null
//it works
使用null 参数它可以工作,但我不喜欢在我的网址上看到null。
我想要"":
https://myliferay.com/example-portlet/-/example-portlet/search/idTable-
//Doesnt work
但它不起作用,就像当参数为空时,URL 与友好的 URL 模式不匹配。
<route>
<pattern>/search/idTable-{idTable}</pattern>
<generated-parameter name="idTable">{idTable}</generated-parameter>
<implicit-parameter name="p_p_lifecycle">0</implicit-parameter>
<!--more implicit params-->
</route>
如何指定参数的可选性?
【问题讨论】:
-
不确定你从哪里得到
null参数:如果你自己生成它,你能把它生成为"",例如空字符串?还是将其转换为这种表示形式? -
@OlafKock 已经有一个空字符串
"",但空参数与友好 URL 模式不匹配。使用null可以。我只是做了相反的事情,我将我的""更改为null以使其正常工作,但正如我所说,更倾向于不要在 URL 中显示null
标签: liferay liferay-6 friendly-url