【发布时间】:2019-06-14 04:13:35
【问题描述】:
您好,我在表单中传递信息,一切正常,但是当我填写表单时,它没有传递信息,我收到此错误。
出现意外错误(类型=内部服务器错误,状态=500)。 引起:org.hibernate.exception.ConstraintViolationException:无法执行语句 原因:java.sql.SQLIntegrityConstraintViolationException:列'movie_id'不能为空
我使用的代码如下:
@PostMapping("/save")
public String save(Movie movie) {
savedMovie.save(movie);
return "redirect:/LatestMovies";
}
和
<form th:action="@{/save}" method="post" >
<p><input type="text" id="movie_id" name="movie_id" value="" /></p>
<p><input type="text" id="movie_name" name="movie_name" value="" /></p>
<p><input type="submit" value="save" /></p>
</form>
我相信所有其他代码都是正确的,因为如果我尝试渲染数据库信息我没有问题。
更新
这是完整的html代码。
<div class="container">
<table class="table table-hover">
<tr>
<th>Id</th>
<th>Name</th>
</tr>
<tr th:each="LatestMovies : ${latestMovies}">
<td th:text="${LatestMovies.id}"></td>
<td th:text="${LatestMovies.movieName}"></td>
<td>
<form th:action="@{/save}" method="post" th:object="${newMovie}">
<p><input type="text" id="movie_id" th:field="*{movie_Id}"/></p>
<p><input type="text" id="movie_name" th:field="*{movie_Name}"/></p>
<p><input type="submit" value="save" /></p>
</form>
</td>
</tr>
</table>
【问题讨论】:
-
正如错误所说,当您试图保存到数据库时,您的 movie_id 为空。检查为什么 movie_id 为空
-
你可以看到我在该字段的表单中传递信息
标签: java hibernate spring-boot thymeleaf