Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Spring Boot中使用模板/包含_Java_Spring_Spring Mvc_Spring Boot - Fatal编程技术网

Java 在Spring Boot中使用模板/包含

Java 在Spring Boot中使用模板/包含,java,spring,spring-mvc,spring-boot,Java,Spring,Spring Mvc,Spring Boot,我正在“开发”一个使用SpringBoot制作的应用程序,我不太确定如何管理模板 我想到了两种方法: 使用自定义标记并将HTML/JSP文件的值作为字符串返回并使用它 像这样的 不常见的事情 您可以使用Thymeleaf。然后你可以用 <!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head th:replace="common/header :: common-hea

我正在“开发”一个使用SpringBoot制作的应用程序,我不太确定如何管理模板

我想到了两种方法:

使用自定义标记并将HTML/JSP文件的值作为字符串返回并使用它

像这样的


不常见的事情

您可以使用Thymeleaf。然后你可以用

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

<head th:replace="common/header :: common-header" />

<body>

    <div th:replace="common/navbar :: common-navbar" />
    <your content here>
</body
</html>


非常感谢,我没听说过这件事。不客气。我正在创建一个在线课程,教你如何使用Spring Boot、Thymeleaf、Bootstrap、AWS和Stripe从头创建一个网站。在本课程中,我将展示上述主题以及更多内容。如果你愿意,你可以在这里注册你的兴趣:课程开放注册时会通知你。
<head th:fragment="common-header">

<title>DevOps Buddy</title>

<!-- Bootstrap core CSS -->
<link th:href="@{/webjars/bootstrap/3.3.6/css/bootstrap.min.css}"
      rel="stylesheet" media="screen" />

<!-- Custom styles for this template -->
<link type="text/css" th:href="@{/css/styles.css}" rel="stylesheet" media="screen"/>
<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>