我的URL有一些参数,因此我使用友好的URL来解决默认情况下生成的难看的URL liferay。
这些参数对有时是空的,这表示它是不需要的,但其他时候给我一些我用于查询的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
参数,它可以工作,但是我不希望在URL上看到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>
如何指定参数的可选性?
就像所有友好url变量都使用正则表达式。您可以像这样更改/覆盖此正则表达式:{idTable:\d}
<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>
我使用.*
作为0个或更多字符的正则表达式,但我不知道它以后是否会给我带来问题。如果有人知道为什么使用该正则表达式不是一个好主意,请对其进行评论。