gpt4 book ai didi

java - Spring MVC 模型不知道我的类

转载 作者:行者123 更新时间:2023-12-02 05:20:47 25 4
gpt4 key购买 nike

我有一个应该直接解决的问题,但我显然做错了什么。我有一个用 Spring MVC 编写的简单网站。我的 JSP 模型不知道我的 NewItem 类..

@RequestMapping(value = "/", method = RequestMethod.GET)
public String newsFeed(Model model) {
try {
initDB();
} catch (Exception e) {
e.printStackTrace();
}

ScanRequest scanRequest = new ScanRequest()
.withTableName("Table1");
ScanResult result = _database.get(scanRequest);
//This will just return a list with filled NewsItems from the database
List<NewsItem> list = getNewsItems(result.getItems());
model.addAttribute("newsList",list);
return "newsfeed";
}

public class NewsItem {
private String url="";
String getUrl(){
return url;
}
void setUrl(String text) {
url = text;
}
private String title="";
void setTitle(String text) {
title = text;
Image = text;
}

String getTitle(){
return title;
}
String Description="";
String Image="";
String Time="";
String Since="";
}

And when im using ${newsList.getTile()} on the JSP side im getting a javax.servlet.jsp.JspException: javax.el.MethodNotFoundException: Method not found: class java.util.ArrayList.getTile() or java.lang.NumberFormatException: For input string:.. when Im trying to use ${newsList.Image}. Does anyone know what Im missing here?

stuff im using in jsp. taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" taglib prefix="spring" uri="http://www.springframework.org/tags" taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" page import="com.kiiak.tennman.NewsItem"

最佳答案

NewsItem 上调用 getTitle(注意拼写),而不是在 List 本身上

<c:forEach var="newsItem" items="${newsList}">
${newsItem.title}
</c:forEach>

关于java - Spring MVC 模型不知道我的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26537322/

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