Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java <;输入>;日期与th:pattern_Java_Spring Mvc_Thymeleaf - Fatal编程技术网

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。要为您的案例编写正确的正则表达式,请参阅