【问题标题】:Setup Spring and Spring-Security to use HTML file设置 Spring 和 Spring-Security 以使用 HTML 文件
【发布时间】:2014-03-22 03:24:02
【问题描述】:

在 Web 应用程序中,我们不想使用 JSP 文件,我们只想使用 HTML 文件。每个视图都是一个模板。

我正在寻找一种方法来设置 spring,spring security 以直接使用 login.html 文件,如果用户验证正确,则通用布局(顶层、左层、右层和中心层和南层)将是显示出来。

【问题讨论】:

    标签: html spring spring-mvc spring-security


    【解决方案1】:

    您正在寻找的是natural templating 解决方案,其中模板直接在 HTML 和 CSS 中构建,标签中只有一些特殊属性,但不需要一组 XML 标签库。

    Thymeleaf 模板技术是一种解决方案 - Comparison of a Thymeleaf template with a JSP in a Spring application

    这是一个模板的样子:

    <!DOCTYPE html>
    
    <html xmlns:th="http://www.thymeleaf.org">
    
    <head>
        <title>Spring MVC view layer: Thymeleaf vs. JSP</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" type="text/css" media="all"
              href="../../css/thvsjsp.css" th:href="@{/css/thvsjsp.css}"/>
    </head>
    
    <body>
    
    <h2>This is a Thymeleaf template</h2>
    
    <form action="#" th:object="${subscription}" th:action="@{/subscribeth}">
    
        <fieldset>
    
            <div>
                <label for="email" th:text="#{subscription.email}">Email: </label>
                <input type="text" th:field="*{email}" />
            </div>
            <div>
                <label th:text="#{subscription.type}">Type: </label>
                <ul>
                    <li th:each="type : ${allTypes}">
                        <input type="radio" th:field="*{subscriptionType}" th:value="${type}" />
                        <label th:for="${#ids.prev('subscriptionType')}"
                               th:text="#{'subscriptionType.'+${type}}">First type</label>
                    </li>
                    <li th:remove="all"><input type="radio" /> <label>Second Type</label></li>
                </ul>
            </div>
    
            <div class="submit">
                <button type="submit" name="save" th:text="#{subscription.submit}">Subscribe me!</button>
            </div>
    
        </fieldset>
    
    </form>
    
    </body>
    
    </html>
    

    【讨论】:

    • 我想知道我们是否可以用 Thymeleaf 做这些事情:我想像这样拆分网站:北部南部南部东部西部中心部分所以这部分可能是在 layout.html 当我到达网站时,我想在中心部分注入 login.html 的内容。那么如果可以的话,怎么说我的第一个网页是layout.html,怎么注入呢?
    • 看看这个带有页眉和页脚的例子thymeleaf.org/petclinic.html
    猜你喜欢
    • 1970-01-01
    • 2018-02-09
    • 2014-07-25
    • 2013-11-01
    • 2013-11-12
    • 2014-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多