加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

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

发布时间:2020-12-14 18:35:11 所属栏目:资源 来源:网络整理
导读:我是 Spring MVC的新手,也是ThymeLeaf的绝对新手. 所以我正在开发一个使用TymeLeaf作为视图技术的Web应用程序,我必须使用这个Jquery Validation Plugin:http://jqueryvalidation.org/ 所以我过去曾将它用于JSP页面. 如文档中所示:http://jqueryvalidation.
我是 Spring MVC的新手,也是ThymeLeaf的绝对新手.

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

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

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

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

<input id="cemail" type="email" name="email" required>

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

<input id="nome" name="nome" type="text" th:value="*{nome}" required></input>

但问题是现在我在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)

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

解决方法

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

尝试:

<input id="nome" name="nome" type="text" th:value="*{nome}" th:required="required"></input>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读