gpt4 book ai didi

java - Spring
转载 作者:行者123 更新时间:2023-12-01 22:40:54 27 4
gpt4 key购买 nike

我正在做一个小型的 spring 项目,当我尝试显示数据迭代 resultList 时遇到问题,结果列表已设置,并且 foreach 循环超过 4 次,因为项目有,但给我一个异常(exception),经过我意识到项目是检索但如果它们只是对象而不是 porper 强制转换类结果,因此当我尝试调用 getUrl() 方法时它会崩溃(如果我调用 toString 工作正常)。

这就是 Controller

 @RequestMapping(value = "/search", method = RequestMethod.GET)
public ModelAndView home(ModelMap model,@RequestParam(required=false,value="") String name) {

List<Result> result = googleSearchService.doSearch(name);
modelAndView.addObject("resultList",result);//<- after debub list is full of Result items
return modelAndView;
}

这就是 View

<c:forEach items="${resultList}" var="item">
<li><c:out value="${item.getUrl()}"/></li>
</c:forEach>

结果类是一个内部类:

public class GoogleResults {


private ResponseData responseData;

public ResponseData getResponseData() {
return responseData;
}

public void setResponseData(ResponseData responseData) {
this.responseData = responseData;
}

public String toString() {
return "ResponseData[" + responseData + "]";
}



static class ResponseData {

private List<Result> results;

public List<Result> getResults() {
return results;
}

public void setResults(List<Result> results) {
this.results = results;
}

public String toString() {
return "Results[" + results + "]";
}
}


static class Result {

public String url;

private String title;

public String getUrl() {
return url;
}

public String getTitle() {
return title;
}

public void setUrl(String url) {
this.url = url;
}

public void setTitle(String title) {
this.title = title;
}

public String toString() {
return "Result[url:" + url + ",title:" + title + "]";
}
}
}

追踪:

ava.lang.NullPointerException javax.el.BeanELResolver.invoke(BeanELResolver.java:159) org.apache.jasper.el.JasperELResolver.invoke(JasperELResolver.java:147) org.apache.el.parser.AstValue.getValue(AstValue.java:157) org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:187)

最佳答案

Result 应标记为 public

关于java - Spring <c :foreach issue jSTL java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26162610/

27 4 0

Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com