SpringBoot 项目中Bootstrap-table 的使用

 1、引入 css 和 js

bootstrap.min.css

jquery-1.12.4.js

bootstrap-table.min.css

/bootstrap-table.min.js

bootstrap-table-zh-CN.min.js

2、加入页面要展示到的 id

  <table id="example" border="1">
  </table>

3、初始化

$('#example').bootstrapTable({
    url: '/admin/getlist',
    method: 'post',
    striped: true,
    columns: [
       {
         field: 'index',
         title: '序号',
         formatter:indexFormatter
      },
      {
         field: 'field1',
         title: 'field1 名字'
      }
    ]
});

完整示例代码如下:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" >
<html>
  <head>
    <title>后台管理</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
	  <link th:href="@{/css/manage.css}" rel="stylesheet"/>
	  <link th:href="@{/vender/bootstrap/3.3.7/css/bootstrap.min.css}" rel="stylesheet"/>

  </head>
  
  <body>

  <h3 style="display:none" th:text="'登录用户:' + ${name}"></h3>

  <a href="/logout" style="float:right;maigin-right:20px;font-size:20px">注销登陆&nbsp;&nbsp;&nbsp;&nbsp;</a>
  <div class="header">
	  <h1 style="font-size:25px;text-align:center;line-height:50px">列表</h1>
  </div>
  <table id="example" border="1">
  </table>


  </body>
  <script th:src="@{/vender/jquery/jquery-1.12.4.js}"></script>
  <script th:src="@{/js/CommonConstant.js}"></script>
  <script th:src="@{/js/manage.js}"></script>

  <!-- Latest compiled and minified CSS -->
  <link rel="stylesheet" th:href="@{/vender/bootstrap-table/1.12.1/bootstrap-table.min.css}">

  <!-- Latest compiled and minified JavaScript -->
  <script th:src="@{/vender/bootstrap-table/1.12.1/bootstrap-table.min.js}"></script>

  <!-- Latest compiled and minified Locales -->
  <script th:src="@{/vender/bootstrap-table/1.12.1/locale/bootstrap-table-zh-CN.min.js}"></script>
<script>
	 initData();
    function initData(){

    $('#example').bootstrapTable({
    url: '/admin/getlist',
    method: 'post',
    striped: true,
    columns: [
       {
         field: 'index',
         title: '序号',
         formatter:indexFormatter
      },
      {
         field: 'field1',
         title: 'field1 名字'
      }
    ]
  });
}
</script>
</html>

提示:后端返回数据是加上注解 @Responsebody的 List<POJO> 集合,即 json数组

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值