【发布时间】:2019-12-10 04:42:21
【问题描述】:
我正在建立一个新网站,我希望有多个文件用于可重用组件(页眉、页脚、常用导入、脚本等)。我还想为每个布局(结合我定义的组件)创建文件,例如“主应用程序”、“全屏仪表板”等。 最后,我想创建只包含我需要的内容的页面,然后将其插入到我选择的布局中。
类似这样的:Diagram of files
我查看了this question,但这需要我以我的内容作为参数调用 java 布局,而不是在我的内容上定义要使用的布局。
我也考虑过只使用我的“布局”作为模板,然后复制并粘贴到新的“内容”文件中并编辑占位符。
这是一个示例控制器:
@View("ticketing/home")
@Get("/")
public HttpResponse home() {
final Map<String, Object> resultMap = new HashMap<>();
resultMap.put("requests", ticketingClient.getSummaryRequests()); //Returns a list of tickets to be displayed.
return HttpResponse.ok(resultMap); //Maps the resultMap variable to the ticketing/home thymeleaf template
}
这就是我希望我的内容文件结构的方式:
<html>
<head>
<title>Tickets</title>
</head>
<body>
<div>
<p>My Content is here!</p>
<img src="wow.jpeg">
</div>
</body>
</html>
这就是我现在的布局:
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Application Layout</title>
<th:block th:include="./fragments/head.html :: imports"></th:block>
</head>
<body>
<div id="wrapper">
<!-- Sidebar Menu -->
<div th:replace="./fragments/sidebar.html :: sidebar"></div>
<div id="page-wrapper" class="gray-bg">
<!-- Navigation Menu -->
<div th:replace="./fragments/topbar.html :: topbar"></div>
<!-- Page Header -->
<div th:replace="./fragments/pageheader.html :: pageheader"></div>
<!-- Main Content -->
<div class="wrapper wrapper-content animated fadeInUp" th:fragment="content">
<div class="row">
<div class="col-lg-12">
<div class="wrapper wrapper-content">
<p>Content here</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div th:replace="./fragments/footer.html :: footer"></div>
<th:block th:replace="./fragments/scripts.html :: scripts"></th:block>
</body>
</html>
我希望能够使用相同的 java 语法(带有注释)来使用我的视图。
我宁愿在内容文件中进行更多更改,而不是在布局文件中进行更改。
【问题讨论】:
标签: java html model-view-controller thymeleaf