2017-04-23 3 views
0

埋め込みTomcat + Thymeleafテンプレートエンジンを使用して、Spring Initializrを使用してSpring Boot Webアプリケーションを生成しました。 私はこのThymeleafのテンプレートSpring Tool Suiteを使用したThymeleafテンプレートの終了タグがありませんバージョン:3.8.4.RELEASE

<!DOCTYPE html> 
<html lang="en" xmlns:th="http://www.thymeleaf.org"> 

<body> 

    <div th:fragment="common-navbar" class="navbar navbar-inverse navbar-fixed-top" role="navigation"> 
     <div class="container"> 
      <div class="navbar-header"> 
       <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse"> 
        <span class="sr-only">Toggle navigation</span> 
        <span class="icon-bar"></span> 
        <span class="icon-bar"></span> 
        <span class="icon-bar"></span> 
       </button> 
      </div> 
      <div class="collapse navbar-collapse"> 
       <ul class="nav navbar-nav"> 
        <li class="active"><a th:text="#{navbar.home.text}" href="/"></a></li> 
        <li><a th:text="#{navbar.about.text}" href="/about"></a></li> 
        <li><a th:text="#{navbar.contact.text}" href="/contact"></a></li> 
       </ul> 

       <ul class="nav navbar-nav navbar-right"> 
        <li th:if="${#authorization.expression('!isAuthenticated()')}"> 
         <a th:href="@{/login}" th:text="#{navbar.login.text}" /> 
        </li> 
        <li th:if="${#authorization.expression('isAuthenticated()')}"> 
         <form id="f" th:action="@{/logout}" method="post" role="form" class="navbar-form"> 
          <button type="submit" th:text="#{navbar.logout.text}" class="btn btn-primary" /> 
         </form> 
        </li> 
       </ul> 
      </div><!--/.nav-collapse --> 
     </div> 
    </div> 

</body> 
</html> 

を持っている。しかし、私は2つの警告No end tag (</a>)を持っています。 & No end tag (</button>)

+1

この警告は、おそらくいくつかのブラウザは 'と' 'と書く方が安全です。さらに、空の 'a'や' button'を持つのは普通の習慣ではありません。特殊なスタイルが適用されている場合( 'display'の変更や背景画像の設定など)にのみ表示されます。あなたが使用した発電機がこれらの折り畳まれたタグフォームを生成したという事実と混同していますか? –

答えて

0

あなたがspring-boot-starter-thymeleaf依存関係を使用する場合は、あなたのpom.xml

<properties> 
    <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version> 
    <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version> 
</properties> 

を追加する必要があります。

これは、MavenにThymeleaf 3を使用させます。デフォルトのThymeleaf 2は、純粋なHTML5をサポートしていません。ここ

詳細情報:https://docs.spring.io/spring-boot/docs/current/reference/html/howto-spring-mvc.html#howto-use-thymeleaf-3

0

Thymeleafは無効なHTMLを表示しないようにします。 abuttonタグを自己囲みで使用していることは、HTML5標準によれば無効です。

あなたはW3バリデータページにHTMLコードの検証を確認することができます。https://validator.w3.org

を自己囲まabuttonタグを使用してHTMLコードを試してみて、その結果を参照してください。

Thymeleafは、HTMLコードの検証ではそれほど難しくありません。 W3では、button要素にあるtitle属性が見つからないとエラーと表示されます。しかし、thymeleafはそれに誤りを与えません。

それにもかかわらず、 Thymeleafにとっては、必要なときにHTMLコードで囲みタグが欠けてはならないことが重要です。

関連する問題