我陷入了一个所谓的简单问题。 我有时间的HTML领域。我想通过用户输入来节省数据库中的时间。
我的html输入:
<input type="time" th:field="*{startTime}"/>
我在模型类中尝试了不同的方法。
import java.time.LocalDateTime;
.....
@Temporal(TemporalType.TIME)
@DateTimeFormat(iso = ISO.TIME)
private LocalDateTime startTime;
这会导致在启动应用程序时出错:@Temporal仅应在java.util.Date或java.util.Calendar上设置。
我尝试先删除@Temporal,然后删除
import java.sql.Time;
....
private Time startTime;
在保存表单的两种情况下,我都遇到错误:object ='process'的验证失败。错误计数:1
我指的是这篇文章中被接受的答案-Spring boot / Thymeleaf - Getting Time from input
请帮助。
更新:pom.xml依赖性和整个错误
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.3.Final</version>
</dependency>
</dependencies>
Whitelabel错误页面此应用程序没有针对 /错误,因此您将其视为备用。
Sun Jul 29 CEST 2018有一个意外错误(type = Bad 请求,状态= 400)。对象=“进程”的验证失败。错误 数:1
答案 0 :(得分:0)
目前,我已经使用“ p”解决了它
<input type="datetime-local" th:field="*{time}"/>
在模型类中
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm")
private LocalDateTime time;
我提到了这篇文章中给出的第一个答案-Spring with Thymeleaf binding date in html form