跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • Thymeleaf 中,后台能对 fragment 传值吗?
未分類
21 5 月 2020

Thymeleaf 中,后台能对 fragment 传值吗?

Thymeleaf 中,后台能对 fragment 传值吗?

資深大佬 : ufan0 55

Spring boot 程序中,后台对 thymeleaf 视图传值我知道, 控制方法里 model.addAttribute()就行了,但是能否对 fragment 传值呢?

未找到有帮助的信息,故发帖询问,感激不尽。

大佬有話說 (7)

  • 資深大佬 : ysyk

    是的,可以。与引用的页面其他参数相同。

  • 資深大佬 : ysyk

    我的写法 <div th:replace=”header :: footer”></div>

    <div th:fragment=”footer”>

    </div>

  • 主 資深大佬 : ufan0

    @ysyk #2 首先感谢回复,应该是我没表达清楚想询问的点;

    我是想知道后台对 fragment 传值

  • 資深大佬 : Andy00

    可以,刚刚用了这功能。像调用函数一样往需要传参数的 fragment 里放入参数就行了,参考我的代码
    “`html
    <div th:replace=”commons/bar::sidebar(activeURI=’kpi’, employees=${employees})”></div>
    “`
    employees 是一个在 model 里传过来的 list

  • 資深大佬 : Andy00

    咦居然不支持代码标签。
    activeURI 和 employees 就是两个传到 sidebar fragment 里的参数

  • 資深大佬 : iwiki

    <!– 菜单递归 –>
    <th:block th:fragment=”listmenu(menus)”>
    <th:block th:each=”menu : ${menus}”>
    <th:block th:if=”${menu.getMenus().size()>0}”>
    <li class=”nav-item has-treeview”>
    <a href=”#” class=”nav-link”>
    <i class=”nav-icon fas fa-tachometer-alt”></i>
    <p>
    <span th:text=”${menu.getName()}”></span>
    <i class=”right fas fa-angle-left”></i>
    </p>
    </a>
    <ul class=”nav nav-treeview”>
    <th:block th:include=”this::listmenu(${menu.getMenus()})”/>
    </ul>
    </li>
    </th:block>
    <th:block th:if=”${menu.getMenus().size()==0}”>
    <li class=”nav-item”>
    <a href=”#” th:href=”${menu.getUri()}” class=”nav-link”>
    <i class=”far fa-circle nav-icon”></i>
    <p th:text=”${menu.getName()}”></p>
    </a>
    </li>
    </th:block>
    </th:block>
    </th:block>

    参考这个吧,函数传值

  • 資深大佬 : ysyk

    Controller 里这样写
    @ModelAttribute(“helper”)
    public Helper helper() {
    return helper;
    }

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具