xmlns:th =“ http://www.thymeleaf.org”不起作用

时间:2019-03-30 21:17:40

标签: spring-boot thymeleaf

谢谢!我已经解决了这个问题!我加
受保护的void addResourceHandlers(ResourceHandlerRegistry注册表) {   Registry.addResourceHandler(“ / static / **”)。addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX +“ / static /”);         super.addResourceHandlers(registry); } 在应用程序中,该错误消失了。

最近,在通过“ spring-boot-in-action”一书学习spring boot时,我遇到了以下问题

程序运行时,我打开网页,发现"Xmlns: th= 'http://www.thymeleaf.org'"行尚未执行,并且CSS文件没有被调用。

下面附带的是HTML源代码。 gradle配置和Web控制器:

HTML源代码:

<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">

<head>
    <title>Reading List</title>
    <link rel="stylesheet"  th:href="@{/style.css}"></link>
</head>

<body>
<h2>Your Reading List</h2>
<div th:unless="${#lists.isEmpty(books)}">
    <dl th:each="book : ${books}">
        <dt class="bookHeadline">
            <span th:text="${book.title}">Title</span> by
            <span th:text="${book.author}">Author</span>
            (ISBN: <span th:text="${book.isbn}">ISBN</span>)

        </dt>
        <dd class="bookDescription">
          <span th:if="${book.description}"
                th:text="${book.description}">Description</span>
            <span th:if="${book.description eq null}">
                No description available</span>
        </dd>
    </dl>
</div>
<div th:if="${#lists.isEmpty(books)}">
    <p>You have no books in your book list</p>
</div>

<hr/>

<h3>Add a book</h3>
<form method="POST">
    <label for="title">Title:</label>
    <input type="text" name="title" size="50"></input><br/>
    <label for="author">Author:</label>
    <input type="text" name="author" size="50"></input><br/>
    <label for="isbn">ISBN:</label>
    <input type="text" name="isbn" size="15"></input><br/>
    <label for="description">Description:</label><br/>
    <textarea name="description" cols="80" rows="5">
        </textarea><br/>
    <input type="submit"></input>
</form>

</body>
</html>

渐变配置

dependencies {

    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    runtimeOnly 'com.h2database:h2'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

网络控制器prtSc :(我不能放图片,对不起,所以我放了一个链接)

<html xmlns="http://www.w3.org/1999/xhtml">

我可以找到此代码,但是

 xmlns:th="http://www.thymeleaf.org" 

消失了。

https://i.stack.imgur.com/pt5Nj.png

0 个答案:

没有答案