thymeleaf制作统计表及导出统计表

thymeleaf制作表格的模板

1.后台

/**
 * @author cqh
 * @create 2022/5/18 15:42
 */
@Controller
@RequestMapping("/system/demo")//前台包地址前缀
public class demo extends BaseController {

    private String prefix = "/system/demo";

    @Autowired
    ISysDeptService sysDeptService;

    @GetMapping("list")
    public String list(ModelMap mmap) {
        mmap.put("user", getSysUser());
        mmap.put("dept", sysDeptService.getCachedDeptById(getSysUser().getDeptId()));
        mmap.put("year", DateUtils.dateTimeNow("yyyy"));
        return prefix + "/list";
    }

    @RequestMapping("list/data")
    public String listData(ModelMap mmap) {
        String sql="SELECT * FROM `table`";
        List<Record> records = Db.find(sql);
        mmap.put("records",records);
        return prefix + "/list_data";
    }
}

2.导出功能list.html

<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <th:block th:include="include :: header('项目名称')" />
</head>
<body class="gray-bg">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <a class="btn btn-info btn-rounded btn-sm" onclick="toExcel()"><i class="fa fa-download"></i>&nbsp;导出</a>
                                <a id="dlink"  style="display:none;"></a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group"></div>
            <div class="col-sm-12 select-table" style="overflow-x: scroll"></div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript" th:inline="javascript">

        function reset(){
            $.modal.loading("正在查询,请稍后...");
            var url = ctx + "/system/demo/list/data";
            $(".select-table").load(url, function (responseTxt,statusTxt,xhr) {
                if (statusTxt === 'success') {
                    $.modal.closeLoading();
                }
            });
        }

        function load(){
            $.modal.loading("正在查询,请稍后...");
            var url = ctx + "/system/demo/list/data";
            $(".select-table").load(url, function (responseTxt,statusTxt,xhr) {
                if (statusTxt === 'success') {
                    $.modal.closeLoading();
                }
            });
        }



        function toExcel(){
            $.widget.tableToExcel('report','reportHead','reportFoot',
                $("#reportYear").text()+"年",
                "Excel表名");
        }

        $(function(){
            reset();
        })
    </script>
</body>
</html>

3.表格模板list_data.html

<div id="table" class="wrapper wrapper-content animated fadeInRight" xmlns:th="http://www.thymeleaf.org">
  <meta charset="UTF-8">
  <style type="text/css">
    /* TABLES */
    .excelTableHead {
      color: black;
      margin-bottom: 6px;
    }

    .excelTable {
      width: auto;
      font-size: 13px;
      color: black;
      border: 1px solid #333333;
    }

    .excelTable > thead > tr > th, .excelTable > thead > tr > td {
      background-color: #333333;
      border-bottom-width: 1px;
    }

    .excelTable > thead > tr > th, .excelTable > tbody > tr > th, .excelTable > tfoot > tr > th, .excelTable > thead > tr > td, .excelTable > tbody > tr > td, .excelTable > tfoot > tr > td {
      border: 1px solid #333333;
    }

    .excelTableFoot {
      color: black;
    }

    @media print {
      #alert_danger {
        display: none;
      }
    }

    table td {
      max-width: 200px;
      max-height: 50px;
      word-wrap: break-word;
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;
      page: true;
    }

    table td:hover {
      white-space: normal;
      overflow: auto;
    }


  </style>
  <table id="reportHead" class="excelTableHead" style="width: 100%" th:with="maxcols=41">
    <tr>
      <td th:colspan="${maxcols}" align="center" style="font-size: 26px; font-weight: 700; padding-bottom: 6px">
        统计表表名
      </td>
    </tr>
    <tr>
      <td colspan="6">地址:[[${dept.deptName}]]</td>
      <td th:colspan="${maxcols-7}" align="right">时间:[[${today}]]</td>
      <td align="right">单位:</td>
    </tr>
  </table>
  <table id="report" class="table excelTable" billstandardborder="1" cellspacing="0" cellpadding="0"
         style="width: 100%">
    <tr>
      <td style="font-weight: 700;"rowspan="2" align="right">序号</td>

      <td style="font-weight: 700;white-space: nowrap" rowspan="2" colspan="2" align="center">1</td>
      <td style="font-weight: 700;white-space: nowrap;" rowspan="2" colspan="2" align="center">2</td>
      <td style="font-weight: 700;white-space: nowrap;" rowspan="2" colspan="2" align="center">3</td>
      <td style="font-weight: 700;white-space: nowrap;" rowspan="2" colspan="2" align="center">4</td>
      <td style="font-weight: 700;white-space: nowrap;" rowspan="2" colspan="2" align="center">5</td>
      <td style="font-weight: 700;white-space: nowrap;" rowspan="2" colspan="2" align="center">6</td>
      <td style="font-weight: 700;white-space: nowrap;" rowspan="2" colspan="2" align="center">7</td>
      <td style="font-weight: 700;white-space: nowrap;" colspan="4" align="center">8</td>
      <td style="font-weight: 700;white-space: nowrap;" colspan="8" align="center">9</td>
      <td style="font-weight: 700;white-space: nowrap;" colspan="10" align="center">10</td>
      <td style="font-weight: 700;white-space: nowrap;" rowspan="2" colspan="2" align="center">11</td>
      <td style="font-weight: 700;white-space: nowrap;" rowspan="2" colspan="2" align="center">12</td>

    </tr>
    <tr>
      <td style="font-weight: 700;white-space: nowrap;" align="center">13</td>
      <td style="font-weight: 700;white-space: nowrap;" align="center">14</td>
      <td style="font-weight: 700;white-space: nowrap;" align="center">15</td>
      <td style="font-weight: 700;white-space: nowrap;" align="center">16</td>


      <td style="font-weight: 700;white-space: nowrap;" align="center">17</td>
      <td style="font-weight: 700;white-space: nowrap;" align="center">18</td>
      <td style="font-weight: 700;white-space: nowrap;" align="center">19</td>
      <td style="font-weight: 700;white-space: nowrap;" align="center">20</td>
      <td style="font-weight: 700;white-space: nowrap;" align="center">21</td>
      <td style="font-weight: 700;white-space: nowrap;" align="center">22</td>
      <td style="font-weight: 700;white-space: nowrap;" align="center">23</td>
      <td style="font-weight: 700;white-space: nowrap;" align="center">24</td>


      <td style="font-weight: 700;white-space: nowrap;" align="center">25</td>
      <td style="font-weight: 700;white-space: nowrap;" align="center">26</td>
      <td style="font-weight: 700;white-space: nowrap;" align="center">27</td>
      <td style="font-weight: 700;white-space: nowrap;" align="center">28</td>
      <td style="font-weight: 700;white-space: nowrap;" align="center">29</td>
      <td style="font-weight: 700;white-space: nowrap;" align="center">30</td>
      <td style="font-weight: 700;white-space: nowrap;" align="center">31</td>
      <td style="font-weight: 700;white-space: nowrap;" align="center">32</td>
      <td style="font-weight: 700;"align="center">33</td>
      <td style="font-weight: 700;white-space: nowrap;" align="center">34</td>

    </tr>

    <tr th:each="item:${list}" >
      <td th:text="${itemStat.count}" ></td>
      <td align="center" colspan="2" >[[${item.get('1')}]]</td>
      <td align="center" colspan="2" >[[${item.get('2')}]]</td>
      <td  colspan="2"  >[[${item.get('3')}]]</td>
      <td colspan="2" >[[${item.get('4')}]]</td>
      <td  colspan="2">[[${item.get('5')}]]</td>
      <td  colspan="2">[[${#numbers.formatDecimal(item.get('6'),1,'COMMA',0,'POINT')}]]</td>
      <td  colspan="2">[[${#numbers.formatDecimal(item.get('7'),1,'COMMA',0,'POINT')}]]</td>
      <td >[[${item.get('13')}]]</td>
      <td > [[${item.get('14')}]]</td>
      <td >[[${item.get('15')}]]</td>
      <td >
        [[${#numbers.formatDecimal(item.get('16'),1,'COMMA',0,'POINT')}]]
      </td>

      <td >[[${item.get('17')}]]</td>
      <td >[[${item.get('18')}]]</td>
      <td >[[${item.get('19')}]]</td>
      <td >[[${item.get('20')}]]</td>
      <td >[[${item.get('21')}]]</td>
      <td >[[${item.get('22')}]]</td>
      <td >[[${item.get('23')}]]</td>
      <td >[[${item.get('24')}]]</td>
      <td >[[${item.get('25')}]]</td>
      <td >[[${item.get('26')}]]</td>
      <td >[[${item.get('27')}]]</td>
      <td >[[${item.get('28')}]]</td>
      <td >[[${item.get('29')}]]</td>
      <td >[[${item.get('30')}]]</td>
      <td >[[${item.get('31')}]]</td>
      <td >[[${item.get('32')}]]</td>
      <td  >[[${item.get('33')}]]</td>
      <td >[[${item.get('34')}]]</td>
      <td  colspan="2">[[${item.get('11')}]]</td>
      <td  colspan="2">[[${item.get('12')}]]</td>

    </tr>
    <tr th:each="item:${Sumlist}">
      <td style="font-weight: 700;white-space: nowrap;"  align="right">合计</td>

      <td align="right" colspan="2"></td>
      <td align="right" colspan="2"></td>

      <td align="right" colspan="2"></td>
      <td align="right" colspan="2"></td>
      <td align="right" colspan="2"></td>
      <td align="right" colspan="2">[[${#numbers.formatDecimal(item.get('Sum6'),1,'COMMA',0,'POINT')}]]</td>
      <td align="right" colspan="2">[[${#numbers.formatDecimal(item.get('Sum7'),1,'COMMA',0,'POINT')}]]</td>
      <td align="right"></td>
      <td align="right"></td>
      <td align="right"></td>
      <td align="right">[[${#numbers.formatDecimal(item.get('Sum16'),1,'COMMA',0,'POINT')}]]</td>
      <td align="right"></td>
      <td align="right"></td>
      <td align="right"></td>
      <td align="right"></td>
      <td align="right"></td>
      <td align="right"></td>
      <td align="right"></td>
      <td align="right"></td>

      <td align="right"></td>
      <td align="right"></td>
      <td align="right"></td>
      <td align="right"></td>
      <td align="right"></td>
      <td align="right"></td>
      <td align="right"></td>
      <td align="right"></td>
      <td align="right"></td>
      <td align="right"></td>
      <td align="right" colspan="2"></td>
      <td align="right" colspan="2"></td>

    </tr>

  </table>
  <table id="reportFoot" class="excelTableFoot" style="width: 100%">
    <tr>
      <td style="width:80px;" colspan="2"></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td colspan="3">负责人:</td>

      <td colspan="3">审核人:</td>

      <td colspan="3">填报人:</td>
    </tr>
  </table>
  <br/>

</div>


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
## springboot整合thymeleaf ### 1. 导入起步依赖 ```xml org.springframework.boot spring-boot-starter-thymeleaf ``` ### 2. 更改引入版本 ```xml 3.0.2.RELEASE 2.1.1 ``` > 1. springboot自带的thymeleaf依赖为2.1.3版本,使用thymeleaf-layout-dialect版本为2以下版本。 > 2. 使用3或3以上的thymeleaf时,需要thymeleaf-layout-dialect的版本为2或以上。 > 3. 锁定thymeleaf版本时不能使用thymeleaf.version标签,会和springboot内部的依赖标签冲突。应当使用springboot-thymeleaf.version标签来锁定版本。 ### 3. 配置文件配置 ```properties spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.check-template-location=true spring.thymeleaf.suffix=.html spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.content-type=text/html spring.thymeleaf.mode=HTML spring.thymeleaf.cache=false ``` > spring.thymeleaf.cache为缓存,需要热部署时,需要设置为false ## 语法 ### 1. 替换标签体内容 ```html 显示欢迎 显示欢迎 ``` ### 2. 替换属性 ```html 显示欢迎 ``` ### 3. 在表达式中访问属性域 ```html 访问属性域 访问请求域 方式一 访问请求域 方式二 访问Session域 访Session域 方式一 访问Application域 方式一 ``` ### 4. 解析url地址 ```html 解析URL地址,获取ContextPath的值 @{}是把ContextPath的值附加到指定的地址前 @{}是把ContextPath的值附加到指定的地址前 ``` ### 5. 直接执行表达式 ```html 直接执行表达式 无转义效果 : [[${attrRequestScope}]] 有转义效果 : [(${attrRequestScope})] ``` ### 6. 分支与迭代 #### 1. if 判断 ```html if判断字符串是否为空 <p th

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值