【问题标题】:Spring MVC does not render html with angularjs directiveSpring MVC 不使用 angularjs 指令渲染 html
【发布时间】:2014-09-10 07:20:18
【问题描述】:

angularjs 特性称为指令导致 spring mvc 中的问题。如果我使用 thymeleaf 来呈现一个带有这样的元素的 html

<div ui-view autoscroll="false"></div>

我遇到了类似的错误

org.xml.sax.SAXParseException: Attribute name "ui-view" associated with an element type "div" must be followed by the ' = ' character.

是否有一个优雅的解决方法,或者我应该使用百里香以外的其他东西?

编辑:

非常感谢您的回答,他们对我帮助很大。

要么编写 xml 代码,要么使用一些解决方法。打开您的 application.properties 并添加以下内容

spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false

【问题讨论】:

标签: java spring angularjs spring-mvc angularjs-directive


【解决方案1】:

只需输入以下代码。基本上它的意思是 HTML 中的每个属性都应该有一个值。当浏览器渲染它时,它无论如何都会如下所示。

<div ui-view="" autoscroll="false"></div>

更新:您还可以在类中或作为元素使用指令。

【讨论】:

  • 感谢您的评论。有没有更优雅的方法来摆脱它而不是更改 html 代码?像ui-view这样不带任何后缀的编码指令是常用的方式。
  • 为避免这种情况,您可以将指令用作类或元素名称,在这种情况下它应该更优雅地工作。 ui-view="" 确实是正确且更通用的方式,因为它也符合 XML 标准。真正限制您的是“thymeleaf”,因为它再次符合正确的 XML 方式。除非您不想从 thymeleaf 进行验证,否则您无能为力,在这种情况下,您可能需要询问 thymeleaf 社区。这里只是一个说明,没有使用指令的“角度”方式。
猜你喜欢
  • 2017-01-04
  • 2016-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 1970-01-01
  • 2013-06-14
相关资源
最近更新 更多