【问题标题】:Click link is not working with thymeleaf点击链接不适用于百里香叶
【发布时间】:2017-12-22 09:32:46
【问题描述】:

我使用 spring boot、thymeleaf 和 bootstrap。

当我进入我的车辆页面时,我想显示所有车辆

@GetMapping("/vehicle")
    public String getVehiclesList(final Model model) {
        List<vehicle> vehicles = vehicleService.getAll();
        model.addAttribute("vehicles", vehicles);
        return "vehicle";
    }

我有一个片段名称:menu

<ul class="nav nav-pills nav-stacked">
    <li role="presentation" data-toggle="tab" class="active">
        <a href="#">Sport</a>
    </li>
    <li role="presentation" data-toggle="tab">
        <a href="/vehicle" th:href="@{/vehicle}">Vehicule</a>
    </li>
</ul>

当我点击车辆时,什么也没有发生...

但如果我将车辆放在网址中,那就行了。

似乎引导事件不起作用

编辑

点击链接时不显示的车辆文件代码

<!DOCTYPE html>
<html th:lang="${#locale.language}" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
    <head th:replace="fragments/head :: head-css"/>
    <body>

        <div class="container-fluid">
            <div class="row">
                <div class="col-sm-2 column menu_side">
                    <div th:replace="fragments/menu :: left-menu"/>
                </div>

                <div id="main" class="col-sm-10 column">    
                    <div role="tabpanel">
                        <form th:action="@{/vehicle-layout}"  method="post">
                            <div class="form-group">
                                <label for="definition">Pick a base vehicle</label>
                                <select class="form-control" id="vehicle">
                                    <option th:value="NULL" selected="selected" > -- select the vehicle --</option>
                                    <option th:each="vehicle : ${vehicles}" th:value="${vehicle.id}" th:text="${vehicle.name}"></option>
                                </select>
                            </div>
                        </form>
                    </div>
                </div>

            </div> 
        </div>       
        <div th:replace="fragments/footer :: footer"/>

    </body>
</html>

编辑 2,如果它删除了

data-toggle="tab"

在菜单中,那个工作......不太明白为什么。

【问题讨论】:

  • &lt;li th:each="vehicle : ${vehicles}"&gt;&lt;span th:text="${vehicle}"&gt;Vehicle Name&lt;/span&gt;&lt;/li&gt; 另外,按照惯例,你的类应该以大写字母开头。
  • 从你的链接中删除 href 属性,你只需要 th:href 属性。我认为这个问题与 Bootstrap 无关。
  • @bphilipnyc 不相关...查看车辆只是不显示...如果我直接在 url 栏中输入:localhost:8080/vehicle,我看到车辆...但当我单击时没有菜单中的链接
  • @tamás-g,什么都不做……写类似 netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/…" th:href="@{/webjars/bootstrap/2.3. 0/css/bootstrap.min.css}" rel="stylesheet" />
  • @bphilipnyc,单击时不显示视图...显示的 html 用于菜单...当我单击菜单的车辆条目时...应该显示车辆视图。 ..如果我把 localhost:8080/vehicle, 在 url 栏中,我会看到车辆..

标签: twitter-bootstrap spring-mvc spring-boot thymeleaf


【解决方案1】:

我使用了这里可用的技术

http://nixmash.com/post/bootstrap-navbar-highlighting-in-thymeleaf

效果很好。

不知道是否可以使用标准引导程序...

【讨论】:

    猜你喜欢
    • 2021-08-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-14
    • 2015-11-29
    • 1970-01-01
    • 2015-12-09
    • 2018-07-08
    相关资源
    最近更新 更多