Home > database >  Loop map with entity
Loop map with entity

Time:10-05

Have some for:

for(int i = 0; i < ids.size(); i  ){
            List<NomenclatureTypeFirst> nmtf = nomenclatureTypeFirstService.getAllByRequest(ids.get(i));
            map.put(ids.get(i), nmtf);
        }

Tried to uset th:text on value like this:

<table>
        <tr th:each="entry, stats : ${map}">
        <td th:text="${entry.key}"></td>
        <td th:text="${entry.value.detname}"></td>
        </tr>
    </table>

But catch:

Property or field 'detname' cannot be found on object of type 'java.util.ArrayList' - maybe not public or not valid?

How can I do this?

CodePudding user response:

The value of your map is a list, so you have to iterate over the values:

<table>
    <tr th:each="entry, stats : ${map}">
    <td th:text="${entry.key}"></td>
    <table>
      <tr th:each="value : ${entry.value}">
         <td th:text="${value.detname}"></td>
      </tr></table>

    </tr>
</table>
  • Related