如何将Java Spring时间属性绑定到Thymeleaf字段?

如何将Java Spring时间属性绑定到Thymeleaf字段?,java,spring,time,thymeleaf,Java,Spring,Time,Thymeleaf,我在Java时间属性绑定到Thymeleaf字段时遇到问题 这是我的HTML代码 <input th:field="*{startTime}" type="text"/> <script> $("#startTime").timepicker({ showSeconds: true, showMeridian: false, secondStep: 1 }); </script> 当我提交表格

我在Java时间属性绑定到Thymeleaf字段时遇到问题

这是我的HTML代码

<input th:field="*{startTime}" type="text"/>
<script>
    $("#startTime").timepicker({
        showSeconds: true,
        showMeridian: false,
        secondStep: 1

    });
</script>
当我提交表格时,我得到了一个例外

Failed to convert property value of type java.lang.String to required
type java.sql.Time for property startTime; nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to
convert from type java.lang.String to type
@javax.validation.constraints.NotNull
@org.springframework.format.annotation.DateTimeFormat java.sql.Time
for value 14:15:41; nested exception is
org.joda.time.IllegalFieldValueException: Cannot parse "14:15:41":
Value 14 for clockhourOfHalfday must be in the range [1,12]
Failed to convert property value of type java.lang.String to required type java.sql.Time for property startTime; nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @javax.validation.constraints.NotNull
@org.springframework.format.annotation.DateTimeFormat java.sql.Time for value 11:15:41; nested exception is
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type org.joda.time.DateTime to type @javax.validation.constraints.NotNull @org.springframework.format.annotation.DateTimeFormat java.sql.Time
如果我插入12小时的时间,我会得到这个例外

Failed to convert property value of type java.lang.String to required
type java.sql.Time for property startTime; nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to
convert from type java.lang.String to type
@javax.validation.constraints.NotNull
@org.springframework.format.annotation.DateTimeFormat java.sql.Time
for value 14:15:41; nested exception is
org.joda.time.IllegalFieldValueException: Cannot parse "14:15:41":
Value 14 for clockhourOfHalfday must be in the range [1,12]
Failed to convert property value of type java.lang.String to required type java.sql.Time for property startTime; nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @javax.validation.constraints.NotNull
@org.springframework.format.annotation.DateTimeFormat java.sql.Time for value 11:15:41; nested exception is
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type org.joda.time.DateTime to type @javax.validation.constraints.NotNull @org.springframework.format.annotation.DateTimeFormat java.sql.Time

如何将Spring-Time属性绑定到Thymeleaf字段?

创建属性类型字符串,创建get-set方法并绑定到视图

private String startTimeString;
和控制器端将值字符串转换为时间并进行设置

setStartTime(Time.valueOf(ModelName.getstartTimeString()));