【发布时间】:2017-12-02 19:41:55
【问题描述】:
我正在使用最新的 spring 和 hibernate。我需要从 jsp 页面获取日期和时间,并希望插入到 mysql 数据库中。我使用 TIMESTAMP 作为一个字段的数据类型。当我尝试保存时,没有错误,但显示“HTTP Status [400] – [Bad Request]”。
最后我发现,日期和时间格式有问题(可能在注解或MySQL数据类型或jsp页面)。因为我尝试在不更改日期时间值的情况下更新表单 (path="startDateTime")。它已成功更新。当我尝试更改日期时间 (path="startDateTime") 中的值时,它显示“HTTP 状态 [400] – [Bad Request]”。 p>
我需要将日期和时间更新到数据库。我尝试了很多方法,但都失败了。
模型类
public class Survey{
//other declaration
@Column(name="startDateTime",columnDefinition="TIMESTAMP")
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(pattern="yyyy-MM-dd'T'HH:mm:ss")
private Date startDateTime;
}
jsp页面
<spring:url value="/survey/save" var="saveURL"></spring:url>
<form:form action="${saveURL}" method="POST" modelAttribute="surveyForm">
//other stuffs
<form:input type="datetime-local" path="startDateTime" />
</form:form>
控制器
public ModelAndView saveSurvey(@ModelAttribute("surveyForm") Survey survey) {
surveyService.saveOrUpdate(survey);
return new ModelAndView("redirect:/survey/list");
}
【问题讨论】:
标签: java mysql spring hibernate jsp