Thymeleaf:找不到null时,获取属性或字段。列表内列表的迭代

时间:2019-03-11 04:23:12

标签: spring thymeleaf

我正在尝试使用百里香在我的html中迭代事务列表(在AllTransaction对象内部)。我进行了调试,并在添加到模型时正确填充了对象。但是在尝试迭代时给出此异常。需要遍历AllTransactions中的另一个事务列表。

AllTransactions.java

has other sign

html代码

public class AllTransactions {

    public String tickerName;

    public List<Transactions> transactions;

    public String getTickerName() {
        return tickerName;
    }

    public void setTickerName(String tickerName) {
        this.tickerName = tickerName;
    }

    public List<Transactions> getTransactions() {
        return transactions;
    }

    public void setTransactions(List<Transactions> transactions) {
        this.transactions = transactions;
    }
}

控制器

<div th:each="itemx : ${alltxs2}">
  <div th:each="tx : ${itemx.transactions}"> 
    <div th:text="${tx.Broker}">
    </div>
  </div>
</div>

StackTrace

  List<AllTransactions> allTransactions= new ArrayList<AllTransactions>();
            AllTransactions alltraTransactions= new AllTransactions();
            for(String ticker: tickers) {
                transactions = m.makeCall(ticker);
                 alltraTransactions.setTransactions(transactions);
                 alltraTransactions.setTickerName(ticker);
                 allTransactions.add(alltraTransactions);
            }

            model.addAttribute("alltxs2",allTransactions);

1 个答案:

答案 0 :(得分:0)

解决方案:- 这是我用来解决问题的解决方案

<div th:each="itemx : ${alltxs}"> 
       <th:block th:each="tx : ${itemx}"> 
       <th:block th:each="x: ${tx.transactions}">
       <div th:text="${x.broker}"></div>
       </th:block>
      </th:block>
   </th:div>