Spring MVC不会使用angularjs指令呈现html

Rud*_*idt 4 java spring spring-mvc angularjs angularjs-directive

angularjs功能被称为指令导致spring mvc中的问题.如果我使用百日咳来渲染带有元素的html

<div ui-view autoscroll="false"></div>
Run Code Online (Sandbox Code Playgroud)

我得到了一个错误

org.xml.sax.SAXParseException: Attribute name "ui-view" associated with an element type "div" must be followed by the ' = ' character.
Run Code Online (Sandbox Code Playgroud)

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

编辑:

非常感谢你的回答,他们帮助了我很多.

要么编码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
Run Code Online (Sandbox Code Playgroud)

The*_*deo 9

只需输入以下代码即可.基本上它说的是HTML中的每个属性都应该有一个值.当浏览器呈现它时,无论如何都会如下所示.

<div ui-view="" autoscroll="false"></div>
Run Code Online (Sandbox Code Playgroud)

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

  • 为避免这种情况,您可以将该指令用作类或元素名称,在这种情况下,它应该更优雅地工作.ui-view =""确实是正确的,更通用的方式,因为它也符合XML标准.真正限制你的是"百里香",因为它再次符合正确的XML方式.除非你不想要百里香叶的验证,否则你不能做那么多,在这种情况下你可能不得不问问百里香社区.这里只是一个注释,没有使用指令的"角度"方式. (2认同)