如何在TymeLeaf页面中将所需的HTML属性正确设置为输入标记?

And*_*ili 7 html model-view-controller spring-mvc java-ee thymeleaf

我是Spring MVC的新手,也是ThymeLeaf的绝对新手.

所以我正在开发一个使用TymeLeaf作为视图技术的Web应用程序,我必须使用这个Jquery Validation插件:http://jqueryvalidation.org/

所以我过去曾将它用于JSP页面.

如文档中所示:http://jqueryvalidation.org/documentation/

我必须将必需的属性添加到我的输入标记,必须由用户填写,如下所示:

<input id="cemail" type="email" name="email" required>
Run Code Online (Sandbox Code Playgroud)

我试着通过这种方式将这个东西放到我的TymeLeaf HTML页面中:

<input id="nome" name="nome" type="text" th:value="*{nome}" required></input>
Run Code Online (Sandbox Code Playgroud)

但问题是现在我在stacktrace控制台中获取此错误消息并且页面未呈现:

15:36:47,180 ERROR [org.thymeleaf.templateparser.ErrorHandler] (http-localhost/127.0.0.1:8080-3) [THYMELEAF][http-localhost/127.0.0.1:8080-3] Fatal error during parsing: org.xml.sax.SAXParseException; lineNumber: 88; columnNumber: 78; Attribute name "required" associated with an element type "input" must be followed by the ' = ' character.
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:196)
    at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:175)  
Run Code Online (Sandbox Code Playgroud)

为什么?怎么了?如何正确地将所需的 HTML属性设置为分解为ThymeLeaf页面的输入标记?

ron*_*rvo 19

使用thymeleaf在HTML5中声明所需属性的正确方法是.th:required="required"

尝试:

<input id="nome" name="nome" type="text" th:value="*{nome}" th:required="required"></input>
Run Code Online (Sandbox Code Playgroud)

  • 是否有人需要它:`th:required="${is_required} ? 'required' : null"` (3认同)