Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.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 Can';t获取使用thymeleaf提交的值_Java_Spring_Spring Boot_Thymeleaf - Fatal编程技术网

Java Can';t获取使用thymeleaf提交的值

Java Can';t获取使用thymeleaf提交的值,java,spring,spring-boot,thymeleaf,Java,Spring,Spring Boot,Thymeleaf,我对thymeleaf是新手,我对如何从html(使用thymeleaf)到Java(Spring Boot)检索字段有疑问。按照代码和我遇到的错误进行操作: HTML(有问题的部分) 实体迁移(Java模型) 错误 2017-11-16 14:01:02.445 ERROR 26932 --- [nio-8080-exec-1] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-1] Ex

我对thymeleaf是新手,我对如何从html(使用thymeleaf)到Java(Spring Boot)检索字段有疑问。按照代码和我遇到的错误进行操作:

HTML(有问题的部分)

实体迁移(Java模型)

错误

    2017-11-16 14:01:02.445 ERROR 26932 --- [nio-8080-exec-1] org.thymeleaf.TemplateEngine             : [THYMELEAF][http-nio-8080-exec-1] Exception processing template "mainForm": An error happened during template parsing (template: "class path resource [templates/mainForm.html]")

org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/mainForm.html]")
(……)

(……)

(……)

我做错了什么?
谢谢。

解析html异常是由于忘记关闭输入标记造成的。请替换:

<input type="number" id="release" placeholder="Release" class="validate" th:value="*{release}">
<input placeholder="Version" id="version" type="number" class="validate">
是由于尝试访问“entity”->entity上的“release”而导致的,entity为null,因此Thymeleaf无法呈现它

必须将属性“实体”添加到模型中才能呈现它。 为了避免SpelEvaluationException,您可以在控制器中检查null:

if (entityManager!= null) {
    model.addAttribute("entity", entityManager);
} else {
    model.addAttribute("entity", new EntityManager());
}

您忘记在输入中使用name属性,并且要关闭输入,请替换:


与:

<input type="number" id="release" placeholder="Release" class="validate" th:value="*{release}"/>
<input placeholder="Version" id="version" type="number" class="validate"/>


html部分是否来自mainForm.htm?形式应答器没有结束。在您发布的html中。该处理程序方法返回
“results”
,这意味着它将显示
模板/results.html
,而不是
模板/mainForm.html
@xavierboculet是的,它是。我只是发布相关部分。请告诉我是否需要包含所有内容。@Andreas该方法将从mainForm.html(我已经有了另一个路径)获取值,确定后,打开results.html部分。你能发布整个mainForm.html吗?乍一看,Thymeleaf似乎无法解析HTML,与java代码无关。我猜你有一些无效的HTML。嗨@Pavle Eftimovski,我包括了关闭标记,但它没有解决问题。目前,我正在使用justonrelease测试是否会发送值。是否必须在所有字段中进行设置才能使其正常工作?请您更具体一点,并附上您现在收到的错误。TnxHi@Pavle Eftimovski,我更新了问题的更多细节。@JuliaBel最新错误org.springframework.expression.spel.SpelEvaluationException:EL1007E:在null上找不到属性或字段“release”,表示您的实体对象位于th:object=“${entity}为空。请检查/发送控制器类中的方法,该方法将实体对象添加到模型变量中。您是对的。我取下了实体对象,页面运行良好。此对象未设置任何值,因此,仅当我在页面上设置某些内容时才应使用它。我理解正确吗?嗨@amir elhajjam,很不幸很遗憾,这并没有解决问题。
Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "release" (template: "mainForm" - line 55, col 23)
org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'release' cannot be found on null
<input type="number" id="release" placeholder="Release" class="validate" th:value="*{release}">
<input placeholder="Version" id="version" type="number" class="validate">
<input type="number" id="release" placeholder="Release" class="validate" th:value="*{release}"/>
<input placeholder="Version" id="version" type="number" class="validate"/>
org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'release' cannot be found on null
if (entityManager!= null) {
    model.addAttribute("entity", entityManager);
} else {
    model.addAttribute("entity", new EntityManager());
}