首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >setTemplateMode("LEGACYHTML5")不适用于胸腺-弹簧-4

setTemplateMode("LEGACYHTML5")不适用于胸腺-弹簧-4
EN

Stack Overflow用户
提问于 2015-08-06 14:07:01
回答 1查看 4.5K关注 0票数 1

我有一个简单的HTML5登录页面:

代码语言:javascript
复制
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
    <body>
       <form th:action="@{/login}" method="post">
           <fieldset style="text-align:center;">
                <input type="text" id="username" name="username" autofocus>
                <input type="password" id="password" name="password">
                <input type="submit" name="submit" value="Login">
           </fieldset>
       </form>
    </body>
</html>

在我的templateResolver配置中,我将其设置为"LEGACYHTML5“,如下所示:

代码语言:javascript
复制
@EnableAutoConfiguration
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Bean public ViewResolver viewResolver() {
        ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
        templateResolver.setTemplateMode("LEGACYHTML5");
        templateResolver.setPrefix("templates/");
        templateResolver.setSuffix(".html");
        SpringTemplateEngine engine = new SpringTemplateEngine();
        engine.setTemplateResolver(templateResolver);

        ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
        viewResolver.setTemplateEngine(engine);
        return viewResolver;
    }

}

当在maven上加载thymeleaf spring-3时,这是非常有效的,但是现在我已经将它更改为thymeleaf spring-4,并得到了解析错误:

代码语言:javascript
复制
org.thymeleaf.exceptions.TemplateInputException: Exception parsing document: template="login", line 35 - column 39
    at org.thymeleaf.templateparser.xmlsax.AbstractNonValidatingSAXTemplateParser.parseTemplateUsingPool(AbstractNonValidatingSAXTemplateParser.java:166)
    at org.thymeleaf.templateparser.xmlsax.AbstractNonValidatingSAXTemplateParser.parseTemplate(AbstractNonValidatingSAXTemplateParser.java:116)
    at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:278)
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1104)
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1060)
    at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1011)
    at org.thymeleaf.spring4.view.ThymeleafView.renderFragment(ThymeleafView.java:335)
    at org.thymeleaf.spring4.view.ThymeleafView.render(ThymeleafView.java:190)
...
Caused by: org.xml.sax.SAXParseException: The element type "input" must be terminated by the matching end-tag "</input>".
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
...

为了澄清,第一个错误指向输入元素上的autofocus属性。我还尝试将templateMode设置为"HTML5",但没有结果。

是不是有什么东西从你的弹簧-3变成了-4?我是不是遗漏了什么?我是否可以使用另一种我不知道的模式(关于thymeleaf spring-4的文档还不是很清楚)?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-06 17:29:42

spring.thymeleaf.mode=LEGACYHTML5添加到application.properties文件,而不是使用基于application.properties的配置,解决了这个问题。这需要类路径中的NekoHTML版本1.9.15或更高版本。

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31857943

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档