无法从输入中获取时间字段,不断收到错误消息:
字段'prepTime'上对象'recipe'中的字段错误:被拒绝的值[04:00];代码[typeMismatch.recipe.prepTime,typeMismatch.prepTime,typeMismatch.java.sql.Time,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable:codes [recipe.prepTime,prepTime];参数[];默认消息[prepTime]]; default message [无法将类型[java.lang.String]的属性值转换为属性'prepTime'的必需类型[java.sql.Time];嵌套异常是org.springframework.core.convert.ConversionFailedException:无法从类型[java.lang.String]转换为类型为[@ org.springframework.format.annotation.DateTimeFormat java.sql.Time]的值为'04:00 “;嵌套异常是org.springframework.core.convert.ConverterNotFoundException:找不到能够从类型[java.util.Date]转换为类型[@ org.springframework.format.annotation.DateTimeFormat java.sql.Time]的转换器]
我的POJO课程:
@Entity
public class Recipe {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Lob
private byte[] photo;
@Size (min=3, max=100, message = "size of field Name must be between 3 and 100")
private String name;
private String description;
@ManyToOne
private Category category;
@DateTimeFormat(pattern = "mm:ss")
private Time prepTime;
@DateTimeFormat(pattern = "mm:ss")
private Time cookTime;
private String addedFlag;
并以html格式输入字段:
<input type="time" th:placeholder="${recipe.prepTime}" th:field="${recipe.prepTime}"/>
那么,我做错了什么?