Dies ist ein Teil meiner HTML-Form.Jackson Serialisierung/Deserialisierung für ZoneDateTime
<form th:object="${applyForm}" class="form-horizontal" role="form" method="post" >
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right"
for="form-field-1"> Start Date </label>
<div class="col-sm-9">
<input type="date" id="form-field-1" th:field="*{startDate}"
placeholder="Completion Date- Estimated"
class="col-xs-10 col-sm-7" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right"
for="form-field-1"> Completion Date </label>
<div class="col-sm-9">
<input type="date" id="form-field-1" th:field="*{completionDate}"
placeholder="Completion Date- Estimated"
class="col-xs-10 col-sm-7" />
</div>
</div>
</form>
Ich benutze Lombak.
public class ApplicationForm implements Serializable {
private static final long serialVersionUID = -2961891549847290936L;
@Column(name = "start_date", nullable = false)
private ZonedDateTime startDate;
//@DateTimeFormat(pattern = "yyyy-mm-dd")
@Column(name = "completion_date", nullable = false)
private ZonedDateTime completionDate;
}
Dies ist der Fehler, wenn ich versuche, mein Formular einzureichen. Ich habe versucht, @DateTimeFormat zu verwenden, aber ich kann diesen Fehler immer noch nicht loswerden. Ich benutze Frühling und Winterschlaf.
Field error in object 'applyForm' on field 'commencementDate': rejected value [2017-11-23]; codes [typeMismatch.applyForm.commencementDate,typeMismatch.commencementDate,typeMismatch.java.time.ZonedDateTime,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [applyForm.commencementDate,commencementDate]; arguments []; default message [commencementDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.time.ZonedDateTime' for property 'commencementDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.persistence.Column java.time.ZonedDateTime] for value '2017-11-23'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2017-11-23]]
Field error in object 'applyForm' on field 'completionDate': rejected value [2017-07-30]; codes [typeMismatch.applyForm.completionDate,typeMismatch.completionDate,typeMismatch.java.time.ZonedDateTime,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [applyForm.completionDate,completionDate]; arguments []; default message [completionDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.time.ZonedDateTime' for property 'completionDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.persistence.Column java.time.ZonedDateTime] for value '2017-07-30'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2017-07-30]]
einfach die geeignete Art verwenden: Sie fordern ein Datum (Jahr + Monat + Tag), um Ihre Benutzer. Kein Nanosekunden-genauer Augenblick mit einer Zeitzone. Verwenden Sie also ein LocalDate, kein ZonedDateTime. –
Derselbe Fehler, obwohl ich zu LocalDate gewechselt habe. Der Fehler ist weg, wenn ich ihn zu Datum ändere. Ich danke dir sehr! – Learner