Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何通过邮递员发送日期并将其保存到数据库?_Java_Spring Boot_Hibernate - Fatal编程技术网

Java 如何通过邮递员发送日期并将其保存到数据库?

Java 如何通过邮递员发送日期并将其保存到数据库?,java,spring-boot,hibernate,Java,Spring Boot,Hibernate,我想通过邮递员提出请求,并用下面的方法接受。据我所知,由于我错误地处理了日期,出现了一个错误。问题:如何通过邮递员发送日期并将其正确保存在数据库中 登录IDEA和邮递员: Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.time.LocalDate` from Strin

我想通过邮递员提出请求,并用下面的方法接受。据我所知,由于我错误地处理了日期,出现了一个错误。问题:如何通过邮递员发送日期并将其正确保存在数据库中

登录IDEA和邮递员:

   Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.time.LocalDate` from String "23/02/2020": Failed to deserialize java.time.LocalDate: (java.time.format.DateTimeParseException) Text '23/02/2020' could not be parsed at index 0; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.time.LocalDate` from String "23/02/2020": Failed to deserialize java.time.LocalDate: (java.time.format.DateTimeParseException) Text '23/02/2020' could not be parsed at index 0
 at [Source: (PushbackInputStream); line: 2, column: 20] (through reference chain: task.homerent.model.Contract["start_date"])]
查询:

{
    "start_date" : "23/02/2020",
    "end_date" : "27/02/2020",
    "id_house" : 2,
    "id_tenant" : 2
}
代码:

合同

@Data
@Entity
@Table(name = "contract", schema = "public")
public class Contract {
    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @ManyToOne
    @JoinColumn(name = "id_house")
    @ToString.Exclude
    @EqualsAndHashCode.Exclude
    @JsonIgnore
    private House house;

    @ManyToOne
    @JoinColumn(name = "id_tenant")
    @EqualsAndHashCode.Exclude
    @ToString.Exclude
    @JsonIgnore
    private User user;

    @Column(name = "end_date")
    private LocalDate end_date;
    @Column(name = "start_date")
    private LocalDate start_date;
}

您需要使用
LocalDate.of(int,int,int)
来构造LocalDate实例

在pom.xml文件中启用依赖关系:

<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jsr310</artifactId>
    <version>2.6.0</version>
</dependency>

是的,我知道,我写过。我想看看如何实现它这是否回答了你的问题?
<dependency>
    <groupId>com.fasterxml.jackson.datatype</groupId>
    <artifactId>jackson-datatype-jsr310</artifactId>
    <version>2.6.0</version>
</dependency>
{
    "start_date" : "2020-03-12",
    "end_date" : "2020-03-19",
    "id_house" : 2,
    "id_tenant" : 3
}