以下代码片段是Spring MVC控制器的一部分。使用commons-collections,它遍历County对象列表并将其转换为String []列表以返回给客户端。使用“searchTerm”变量的值来查找数据。我遇到的问题是每隔一段时间,一个特定的搜索术语会导致转换器抛出异常,因为County .getState()方法似乎返回null。所以我想知道是否使用IntelliJ的调试器,我可以告诉它不断迭代,直到一个变量为空。断点会导致我手动逐步执行每次迭代,但是对于大集合,这可能需要一段时间。使用IntelliJ调试器,是否可以继续通过集合迭代,直到变量返回null?
谢谢。
public List<String[]> cityLookup(@PathVariable String searchTerm) {
List<County> counties = countyService.findAllByPartialCity(searchTerm);
return new ArrayList<String[]>(CollectionUtils.collect(counties, new Transformer() {
@Override
public Object transform(Object o) {
return new String[]{((County) o).getId().getCity(), ((County) o).getState().getStateCode()};
}
}));
}
这正是我需要的!谢谢! – 2013-05-03 13:07:00
@PatrickGrimard很高兴我能帮到你。 – 2013-05-03 13:21:33