Spring表达式语言 – 根据URL映射值(基于路径,不包含主机和端口)

huangapple go评论79阅读模式
英文:

Spring Expression language - map values based on url (based on the path without host and port)

问题

我正在尝试在SpEL(Spring表达式语言)中映射一个值。

我需要根据URL路径映射某些值

https://www1.qa4.testsite.com/sso-login :External
https://www1.qa4.testsite.com/www :Normal
https://www.testsite.com/main/personal :Marketing


除了检查整个字符串值之外,还需要表达式来仅检查路径('sso-login','www','main/personal')

`#map(#requestInfo.httpReferer, 
{ 'https://www1.qa4.testsite.com/sso-login': 'External', 'https://www.testsite.com/main/personal': 'Marketing', 'https://www1.qa4.testsite.com/www': 'Normal' }, 'Normal')`
英文:

I am trying to map a value in SpEL (Spring Expression Language).

I need to map certain values based on the url path

https://www1.qa4.testsite.com/sso-login : External
https://www1.qa4.testsite.com/www : Normal
https://www.testsite.com/main/personal : Marketing

What would be the expression to achieve this value other than checking the whole string value. Need expression to check only the path ('sso-logn' , 'www' , 'main/personal')

#map(#requestInfo.httpReferer,
{'https://www1.qa4.testsite.com/sso-login': 'External', 'https://www.testsite.com/main/personal': 'Marketing', 'https://www1.qa4.testsite.com/www': 'Normal'}, 'Normal')

答案1

得分: 0

有一个有效的表达式

#map(#requestInfo?.httpReferer?.split("m/")?.$[true], {'sso-login': 'External', 'www': 'Marketing', 'main/personal': 'Normal'}, 'Normal')


<details>
<summary>英文:</summary>

Got a working expression 

#map(#requestInfo?.httpReferer?.split("m/")?.$[true], {'sso-login': 'External', 'www': 'Marketing', 'main/personal': 'Normal'}, 'Normal')


</details>



huangapple
  • 本文由 发表于 2020年9月14日 21:13:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/63885080.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定