html layout:fragment (Spring Boot + Java) 中的 h2 数据库控制台
h2 database console in html layout:fragment (Spring Boot + Java)
我正在开发 Spring 启动应用程序。我使用 main.html
作为嵌入所有其他 .html 的框架。为此,我使用 layout:fragment
.
我的导航栏中还有一个“DATABASE”菜单,它指向 H2 数据库控制台。
是否可以将此控制台作为片段嵌入到 main.html
中?
main.html
的body:
<body>
<div class="container">
<nav class="navbar navbar-default">
<ul class="nav navbar-nav">
<li><a href="/">HOME</a></li>
<li><a href="/blogs">BLOGS</a></li>
<li><a href="/bloggers">BLOGGERS</a></li>
<li sec:authorize="hasRole('ROLE_ADMIN')"><a href="/admin">ADMIN</a></li>
<li sec:authorize="hasRole('ROLE_ADMIN')"><a href="/database">DATABASE</a></li>
<li><a href="/signup"><button id="signup-small-button" class="btn btn-success">SIGN UP</button></a></li>
</ul>
<div class="navbar-right">
<form sec:authorize="!isAuthenticated()" th:action="@{/loginfailed}" method="post">
<input th:value="${username}" type="text" name="username" placeholder="username" required class="login-input"/>
<input th:value="${password}" type="password" name="password" placeholder="password" required class="login-input"/>
<button type="submit" id="login-button" class="btn btn-success btn-xs">Log in</button>
</form>
<div sec:authorize="isAuthenticated()">
<span th:text="${#authentication.name + ' | '}" class="black"></span>
<form th:action="@{/logout}" method="post" id="logout-button-form">
<button type="submit" id="logout-button" class="btn btn-primary btn-xs">Log out</button>
</form>
</div>
</div>
</nav>
<div layout:fragment="content"></div>
<footer>
<hr/>
<p id="footer">Made by hazazs (©Copyrighted by hazazs™)</p>
</footer>
</div>
</body>
解决方案是 database.html
文件:
<html layout:decorate="~{layout/main}">
<head>
<title>DATABASE</title>
</head>
<body>
<div layout:fragment="content" class="center">
<iframe src="http://IP:PORT/h2" id="h2-console"></iframe>
</div>
</body>
</html>
当然还有“/database”的 @RequestMapping,returns 这个 html。
@RequestMapping(value = "/database", method = RequestMethod.GET)
public String database() {
return "database";
}
application.yaml:
spring:
h2:
console:
enabled: true
path: /h2
我正在开发 Spring 启动应用程序。我使用 main.html
作为嵌入所有其他 .html 的框架。为此,我使用 layout:fragment
.
我的导航栏中还有一个“DATABASE”菜单,它指向 H2 数据库控制台。
是否可以将此控制台作为片段嵌入到 main.html
中?
main.html
的body:
<body>
<div class="container">
<nav class="navbar navbar-default">
<ul class="nav navbar-nav">
<li><a href="/">HOME</a></li>
<li><a href="/blogs">BLOGS</a></li>
<li><a href="/bloggers">BLOGGERS</a></li>
<li sec:authorize="hasRole('ROLE_ADMIN')"><a href="/admin">ADMIN</a></li>
<li sec:authorize="hasRole('ROLE_ADMIN')"><a href="/database">DATABASE</a></li>
<li><a href="/signup"><button id="signup-small-button" class="btn btn-success">SIGN UP</button></a></li>
</ul>
<div class="navbar-right">
<form sec:authorize="!isAuthenticated()" th:action="@{/loginfailed}" method="post">
<input th:value="${username}" type="text" name="username" placeholder="username" required class="login-input"/>
<input th:value="${password}" type="password" name="password" placeholder="password" required class="login-input"/>
<button type="submit" id="login-button" class="btn btn-success btn-xs">Log in</button>
</form>
<div sec:authorize="isAuthenticated()">
<span th:text="${#authentication.name + ' | '}" class="black"></span>
<form th:action="@{/logout}" method="post" id="logout-button-form">
<button type="submit" id="logout-button" class="btn btn-primary btn-xs">Log out</button>
</form>
</div>
</div>
</nav>
<div layout:fragment="content"></div>
<footer>
<hr/>
<p id="footer">Made by hazazs (©Copyrighted by hazazs™)</p>
</footer>
</div>
</body>
解决方案是 database.html
文件:
<html layout:decorate="~{layout/main}">
<head>
<title>DATABASE</title>
</head>
<body>
<div layout:fragment="content" class="center">
<iframe src="http://IP:PORT/h2" id="h2-console"></iframe>
</div>
</body>
</html>
当然还有“/database”的 @RequestMapping,returns 这个 html。
@RequestMapping(value = "/database", method = RequestMethod.GET)
public String database() {
return "database";
}
application.yaml:
spring:
h2:
console:
enabled: true
path: /h2