[英]Java JXPath iterating through List
JXPath search in list of bean for rateCode value by empty iterator. JXPath通过空的迭代器在bean列表中搜索rateCode值。
I have list of beans where i want to fetch all items having rateCode=R1 following is my code. 我有要在其中提取所有具有rateCode = R1的项目的bean列表,以下是我的代码。
class MyBean{
private String rateCode;
public String getRateCode(){
return this.rateCode;
}
public void setRateCode(String rateCode){
this.rateCode=rateCode;
}
}
List<MyBean> list = loadTestData();
JXPathContext ctx = JXPathContext.newContext(list);
Iterator iter = authSrcContext.iterate("*[rateCode='R1']");
while(iter.hasNext()){
Object bp = iter.next();
MyBean bean = (MyBean)bp;
}
Assuming the fact you don't use ctx but authSrcContext is a typo, you need a dot to reference the current list, in this case. 假设您实际上没有使用ctx,但是authSrcContext是一个错字,在这种情况下,您需要一个点来引用当前列表。
JXPathContext ctx = JXPathContext.newContext(list);
Iterator<Object> iter = ctx.iterate(".[rateCode='R1']");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.