英文:
h2 database console in html layout:fragment (Spring Boot + Java)
问题
<body>
<div class="container">
<nav class="navbar navbar-default">
<ul class="nav navbar-nav">
<li><a href="/">主页</a></li>
<li><a href="/blogs">博客</a></li>
<li><a href="/bloggers">博主</a></li>
<li sec:authorize="hasRole('ROLE_ADMIN')"><a href="/admin">管理员</a></li>
<li sec:authorize="hasRole('ROLE_ADMIN')"><a href="/database">数据库</a></li>
<li><a href="/signup"><button id="signup-small-button" class="btn btn-success">注册</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="用户名" required class="login-input"/>
<input th:value="${password}" type="password" name="password" placeholder="密码" required class="login-input"/>
<button type="submit" id="login-button" class="btn btn-success btn-xs">登录</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">登出</button>
</form>
</div>
</div>
</nav>
<div layout:fragment="content"></div>
<footer>
<hr/>
<p id="footer">由hazazs制作(版权所有©hazazs™)</p>
</footer>
</div>
</body>
英文:
I'm working on a Spring Boot application. I use main.html
as a frame around all the other .htmls embedded. For this I use layout:fragment
.
I also have a "DATABASE" menu in my navigaton bar, which points to the H2 database console.
Is it possible to embed this console into the main.html
as fragment?
main.html
's 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>
答案1
得分: 1
以下是翻译好的内容:
解决方案是一个名为 database.html
的文件:
<html layout:decorate="~{layout/main}">
<head>
<title>数据库</title>
</head>
<body>
<div layout:fragment="content" class="center">
<iframe src="http://IP:PORT/h2" id="h2-console"></iframe>
</div>
</body>
</html>
当然还有一个用于路径为 "/database" 的 @RequestMapping,用于返回这个 HTML。
@RequestMapping(value = "/database", method = RequestMethod.GET)
public String database() {
return "database";
}
application.yaml:
spring:
h2:
console:
enabled: true
path: /h2
英文:
The solution was a database.html
file:
<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>
And of course a @RequestMapping for "/database" which returns this html.
@RequestMapping(value = "/database", method = RequestMethod.GET)
public String database() {
return "database";
}
application.yaml:
spring:
h2:
console:
enabled: true
path: /h2
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论