我有一个包含航班号和门号的java对象列表:
public class Flight {
public String flightNumber;
public String gateNumber;
}
出于这个问题的目的,我的列表包含具有以下航班号和门号的对象:
"AA123" "10"
"BB789" "11"
"BB124" "10"
"AA456" "12"
我知道如果我想在门10选择所有对象,我可以使用以下JXPath表达式(可以工作):
.[gateNumber = "10"]
我需要做的是选择10号门的所有物品,其航班号以" AA"开头。
我已尝试过以下操作,但没有一个能够正常工作:
.[gateNumber = "10" and flightNumber.startsWith("AA")]
.[gateNumber = "10" and flightNumber.substring(0, 2) = "AA"]
.[gateNumber = "10" and substring(flightNumber, 0, 2) = "AA"]
.[gateNumber = "10" and substring($flightNumber, 0, 2) = "AA"]
我的JXPath表达式应该是什么?如果不编写自定义扩展名,它甚至可以吗?
答案 0 :(得分:1)
I could not find a way using native JXPath, so in the end I had to develop an extension that returned true if the contents of the first string parameter started with the contents of the second string parameter:
.[gateNumber = "10" and utils:startsWith(flightNumber, "AA")]
Edit
I haven't tried it, but apparently JXPath supports the starts-with()
function from XPath.