spring bootstarptable动态加载表头

1,通过spring bean 配置文件将 表头模板放到xml 文件里面

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <bean name="userListName" class="com.ali.pims.template.Columns">
        <property name="field" value="name"></property>
        <property name="title" value="名称"></property>
    </bean>
    <bean name="userListLogin" class="com.ali.pims.template.Columns">
        <property name="field" value="loginName"></property>
        <property name="title" value="登录名"></property>
    </bean>
    <bean name="userMenu" class="com.ali.pims.template.Columns">
        <property name="field" value="loginName"></property>
        <property name="title" value="登录名"></property>
    </bean>
    <bean name="userListTemplate" class="com.ali.pims.template.ListTemplate">
        <property name="columns">
            <list>
                <ref bean="userListName" />
                <ref bean="userListLogin" />
            </list>
        </property>
        <property name="name" value="用户"/>
        <property name="resourcesUrl" value="user"></property>
        <property name="imgResources">
            <map>
                <entry key="pechorin" value="pechorin@hero.org"/>
                <entry key="raskolnikov" value="raskolnikov@slums.org"/>
                <entry key="stavrogin" value="stavrogin@gov.org"/>
                <entry key="porfiry" value="porfiry@gov.org"/>
            </map>
        </property>
    </bean>
</beans>
public class ListTemplate {
    private List<Columns> columns;
    private  String title;
    /**
     * 资源路径
     */
    private  String resourcesUrl;
    /**
     * 名称
     * @return
     */
    private String name;
    /**
     * 图片
     */
    private Map<String,TemplateResources> imgResources;

    public Map<String, TemplateResources> getImgResources() {
        return imgResources;
    }

    public void setImgResources(Map<String, TemplateResources> imgResources) {
        this.imgResources = imgResources;
    }

    public String getResourcesUrl() {
        return resourcesUrl;
    }

    public void setResourcesUrl(String resourcesUrl) {
        this.resourcesUrl = resourcesUrl;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Columns> getColumns() {
        return columns;
    }

    public void setColumns(List<Columns> columns) {
        this.columns = columns;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
}

public class Columns {
    private String field;
    private String title;

    public String getField() {
        return field;
    }

    public void setField(String field) {
        this.field = field;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
}

实例化bean 的方式 读取模板

 ListTemplate template = BeansUtils.getBean("userListTemplate");
 model.addAttribute("columns", JSON.toJSON(template.getColumns()));
   <!-- Latest compiled and minified JavaScript -->
    <script src="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.js"></script>
    <!-- Latest compiled and minified Locales -->
    <script src="https://unpkg.com/bootstrap-table@1.15.3/dist/locale/bootstrap-table-zh-CN.min.js"></script>
 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <table id="table"></table>
</body>
<script type="text/javascript">
    $('#table').bootstrapTable({
        columns:  JSON.parse('${columns}')
    })
</script>
</html>

项目地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值