Java <;输入>;日期与th:pattern
我正在尝试使用Java <;输入>;日期与th:pattern,java,spring-mvc,thymeleaf,Java,Spring Mvc,Thymeleaf,我正在尝试使用th:pattern作为日期输入表单字段,就像下面使用SpringMVC的thymeleaf模板一样,但运气不好。还有谁经历过类似的事情,并且有一些见解或选择 我尝试了1。硬编码模式 收到的错误: Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "MM/dd/yyyy
th:pattern
作为日期输入表单字段,就像下面使用SpringMVC的thymeleaf模板一样,但运气不好。还有谁经历过类似的事情,并且有一些见解或选择
我尝试了1。硬编码模式
收到的错误:
Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "MM/dd/yyyy"
Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring3.processor.attr.SpringInputGeneralFieldAttrProcessor'
和2。在java代码中设置模板使用的模式
收到的错误:
Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "MM/dd/yyyy"
Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring3.processor.attr.SpringInputGeneralFieldAttrProcessor'
pattern
是input
标签的html5属性
模式
使用验证输入
值。所以插入到模式中的值应该是正确的正则表达式模式
如果您正在使用Thymeleaf的th:
前缀,模板处理器将尝试在Spiring的模型中找到合适的变量,并将其作为属性值插入。Thymeleaf正在使用它的模板
因此,您的第一种方法是不正确的,因为使用了无效的SpringEL表达式
第二种解决方案看起来更好,type=“date”
提供了您想要的东西,但效果很好<代码>${classdate\u format}
看起来像正确的表达式。要了解第二个错误的原因,需要更多代码
无论如何,是否有任何理由使用th:
前缀作为pattern
属性?只有当您想在服务器端动态创建正则表达式模式时,才需要它。但在本例中,正则表达式模式非常简单,所以您可以在不使用th:
的情况下使用attribute。要为您的案例编写正确的正则表达式,请参阅