JXPath search in list of bean for rateCode value by empty iterator.
I have list of beans where i want to fetch all items having rateCode=R1 following is my code.
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.
JXPathContext ctx = JXPathContext.newContext(list);
Iterator<Object> iter = ctx.iterate(".[rateCode='R1']");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.