【问题标题】:: EL1008E: Property or field 'LEVEL' cannot be found on object of type 'java.util.ArrayList' - maybe not public or not valid?:EL1008E:在“java.util.ArrayList”类型的对象上找不到属性或字段“LEVEL”-可能不是公共的或无效的?
【发布时间】:2021-01-22 09:37:27
【问题描述】:

请协助以下。我正在尝试显示从控制器返回的数组列表并将其显示到 Html 表中,但出现上述错误。

这是我的控制器代码:

@GetMapping(value="/chart" )
public List<List<CanvasjsChartData.DataPointModel>> chart(Model modelMap) {
    List<List<CanvasjsChartData.DataPointModel>> dataPointsList = canvasjsChartService.getCanvasjsChartData();
    modelMap.addAttribute("dataPointsList", dataPointsList);
    System.out.println("dataPointsList");
    return dataPointsList;
}

这是我想在其中显示我的列表的表格

<table class="table" id="dataTable" style="width:100%">

<thead>
<th>Level</th>
<th>Occurences</th>
</thead>

<tbody>
<tr th:each="item :${dataPointsList}">
   <td th:text="${item.LEVEL}"> </td>
    <td th:text="${item.OCCURENCES}"> </td>
</tr>
</tr>
</tbody>

我确定 ArrayList 有我需要的数据,如下所示我不知道为什么它给了我错误

【问题讨论】:

    标签: spring-boot spring-mvc arraylist thymeleaf


    【解决方案1】:

    您的调试显示您有一个List&lt;List&lt;CanvasjsChartData.DataPointModel&gt;&gt;(两个列表相互连接)——当您的 HTML 期待 List&lt;CanvasjsChartData.DataPointModel&gt; 时。你应该在你的控制器/模型中通过只返回一个列表来解决这个问题。

    您也可以像这样显示您的 HTML(循环外部数组的第 0 个元素):

    <tr th:each="item :${dataPointsList[0]}">
      <td th:text="${item.LEVEL}" />
      <td th:text="${item.OCCURENCES}" />
    </tr>
    

    【讨论】:

      猜你喜欢
      • 2018-11-20
      • 2020-09-22
      • 2019-12-13
      • 2016-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多