How do I bind the Java spring time attribute to the thymeleaf field?
•
Java
I have a problem binding a java time attribute to the thymeleaf field@ H_ 404_ 7@
<input th:field="*{startTime}" type="text"/> <script> $("#startTime").timepicker({ showSeconds: true,showMeridian: false,secondStep: 1 }); </script>
@NotNull(message = "Start time cannot be empty") private Time startTime; public Time getStartTime() { return startTime; } public void setStartTime(Time startTime) { this.startTime = startTime; }
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
Solution
Create a property type string, create a get set method, and bind it to view @ H_ 404_ 7@
private String startTimeString;
setStartTime(Time.valueOf(ModelName.getstartTimeString()));
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码