Java org.springframework.expression.spel.SpelEvaluationException:EL1008E:属性或字段';最新总病例数';在对象上找不到
我有一个包含以下内容的html页面:Java org.springframework.expression.spel.SpelEvaluationException:EL1008E:属性或字段';最新总病例数';在对象上找不到,java,spring,spring-boot,thymeleaf,Java,Spring,Spring Boot,Thymeleaf,我有一个包含以下内容的html页面: <table> <tr> <th>State</th> <th>Country</th> <th>Total case reported</th> </tr> <tr th:each="locationStat : ${locationStats}">
<table>
<tr>
<th>State</th>
<th>Country</th>
<th>Total case reported</th>
</tr>
<tr th:each="locationStat : ${locationStats}">
<td th:text="${locationStat.state}"></td>
<td th:text="${locationStat.country}"></td>
<td th:text="${locationStat.latestTotalCases}"></td>
</tr>
</table>
在我的服务层上读取CSV并写入对象
@Service
public class CoronavirusDataService {
private static String DATA_URL = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv";
private List<LocationStats> allStats = new ArrayList<>();
public List<LocationStats> getAllStats() {
return allStats;
}
@PostConstruct
@Scheduled(cron = "* 1 * * * *")
public void fetchVirusData() throws IOException, InterruptedException {
List<LocationStats> newStats = new ArrayList<>();
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(DATA_URL)).build();
HttpResponse<String> httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
StringReader csvReader = new StringReader(httpResponse.body());
Iterable<CSVRecord> records = CSVFormat.DEFAULT.withFirstRecordAsHeader().parse(csvReader);
for (CSVRecord record : records) {
LocationStats locationStats = new LocationStats();
locationStats.setState(record.get("Province/State"));
locationStats.setCountry(record.get("Country/Region"));
Integer totalCases = Integer.parseInt(record.get(record.size() - 1));
locationStats.setLatestTotalCases(totalCases);
System.out.println(locationStats);
newStats.add(locationStats);
}
this.allStats = newStats;
}
}
错误表示在对象com.gour.modules.LocationStats上找不到latestTotalCases,但如果您看到我的模型类,它就在那里
不知道我错过了什么,需要你的帮助。我不熟悉这一点,所以请耐心听我的提问。确保getter没有参数
public Integer getLatestTotalCases(int i) {
return latestTotalCases;
}
应该是
public Integer getLatestTotalCases() {
return latestTotalCases;
}
确保getter没有参数
public Integer getLatestTotalCases(int i) {
return latestTotalCases;
}
应该是
public Integer getLatestTotalCases() {
return latestTotalCases;
}
谢谢你的回答,但是你能告诉我为什么它会因为getter而失败吗?简化:因为Spring将尝试调用该getter,但它只调用与Java Bean兼容的getter而不带参数-它无论如何都不知道要传递什么值。这就是为什么会出现“找不到属性或字段”异常。感谢您的回答,但请您告诉我为什么它会因为getter而失败。简化:因为Spring将尝试调用该getter,但它只调用与Java Bean兼容的getter而不带参数-它无论如何都不知道要传递什么值。这就是为什么会出现“找不到属性或字段”异常。