来自数据库的Thymeleaf动态头和内容表

时间:2016-08-03 16:19:16

标签: java spring-mvc thymeleaf spring-restcontroller

我是百里香的新人。我对动态表有疑问。这是我的情况:

[
   {
      "country":"country 1",
      "districs":[
         {
            "district":"district 1",
            "cinemas":[
               {
                  "cinema": "cinema 1"
                  "movie":"Sherlock",
                  "visitor":30
               },{
                  "cinema": "cinema 2"
                  "movie":"Terminator",
                  "visitor":40
               },{
                  "cinema": "cinema 2"
                  "movie":"Tarzan",
                  "visitor":20
               }]
         }, {
            "district":"district 2",
            "cinemas":[
               {
                  "cinema": "cinema 1"
                  "movie":"Sherlock",
                  "visitor":12
               },{
                  "cinema": "cinema 2"
                  "movie":"Terminator",
                  "visitor":41
               },{
                  "cinema": "cinema 2"
                  "movie":"Tarzan",
                  "visitor":24
               }]
            }, {
            "district":"district 3",
            "cinemas":[
               {
                  "cinema": "cinema 1"
                  "movie":"Sherlock",
                  "visitor":12
               },{
                  "cinema": "cinema 2"
                  "movie":"Terminator",
                  "visitor":41
               }]
            }]
    },    {
      "country":"country 2",
      "districs":[
         {
            "district":"district 1",
            "cinemas":[
               {
                  "cinema": "cinema 2"
                  "movie":"Terminator",
                  "visitor":40
               },{
                  "cinema": "cinema 2"
                  "movie":"Tarzan",
                  "visitor":20
               }]
         }, {
            "district":"district 2",
            "cinemas":[
               {
                  "cinema": "cinema 1"
                  "movie":"Sherlock",
                  "visitor":12
               },{
                  "cinema": "cinema 2"
                  "movie":"Tarzan",
                  "visitor":24
               }]
            }, {
            "district":"district 3",
            "cinemas":[
               {
                  "cinema": "cinema 1"
                  "movie":"Sherlock",
                  "visitor":12
               },{
                  "cinema": "cinema 2"
                  "movie":"Terminator",
                  "visitor":41
               }]
            }]
    }]

然后我想要显示如下:

---------------------------------------------------------------------------------------------------------
Movies     |country 1                                   | country 2                                     |
           ----------------------------------------------------------------------------------------------
           |district 1   | district 2  | district 3   | district 1    | district 2    | district 3      |
---------------------------------------------------------------------------------------------------------
Sherlock   | 30          | 12          | 12           | 0             | 12            | 12              |
Terminat   | 40          | 41          | 41           | 40            | 0             | 41              |
Tarzan     | 20          | 24          | 0            | 20            | 24            | 0               |
---------------------------------------------------------------------------------------------------------

我怎样才能在百里香中实现这一目标? 我的代码如下,但仍无法实现此输出。

<table>
        <thead>
          <tr>                    
              <th:block th:each="data : ${countries}">
                   <th th:colspan="${data.districts.size()}" th:text="${data.country}" ></th>
              </th:block>
          </tr>
          <tr>    
             <th:block th:each="data : ${countries}">
                  <th:block th:each="district :${data.districts}">
                      <th th:text="${district.district}"></th>
                   </th:block>
              </th:block>
          </tr>
    <thead>
        <tbody>
           <tr>
             <th:block th:each="data : ${countries}">
                 <th:block th:each="district :${data.districts}">
                      <th:block th:each="cinema :${district.cinemas}">
                         <td th:text="${cinema.visitor}" />
                      </th:block>
                 </th:block>
              </th:block>
          </tr>
        </tbody>
</table>

如果有人有任何想法可以解决这个问题。 顺便说一句,对于json我使用弹簧休息生成。 非常感谢。

0 个答案:

没有答案