如何在Spring JAVA(JPA/Hibernate)中映射MySQL Timestamp字段。

huangapple go评论85阅读模式
英文:

How to map MySQL Timestamp field in Spring JAVA(JPA/Hibernate)

问题

我在寻找在Spring Boot应用程序中如何映射不同类型字段到不同数据库方面遇到了问题。主要,我想知道如何映射MySQL的Timestamp类型,但如果我也能找到不同数据库中每种数据类型的映射集合的链接,那就太好了。

英文:

I am having trouble finding how to map different type of fields for different DBs in a Spring Boot Application. Primarily, I would like to know how to map the MySQL Timestamp but it would be great if I can also find a link to the collection of mappings for every datatype in different DBs.

答案1

得分: 4

  1. 您可以在此处找到标准基本类型的列表。

  2. 您还可以将TIMESTAMP映射到以下Java 8类型

java.time.Instantjava.time.LocalDateTimejava.time.OffsetDateTimejava.time.ZonedDateTime

  1. 您还可以使用过时的java.util.Date(请参见此处):
@Column(name = "`timestamp`")
@Temporal(TemporalType.TIMESTAMP)
private Date timestamp;

但第一种方法更加推荐。

英文:

The list of standard basic types you can find here.

  1. You can map TIMESTAMP to the following Java 8 types:

java.time.Instant, java.time.LocalDateTime, java.time.OffsetDateTime and java.time.ZonedDateTime.

  1. You can also use outdated java.util.Date (see this):
@Column(name = "`timestamp`")
@Temporal(TemporalType.TIMESTAMP)
private Date timestamp;

But the first approach is much more preferable.

huangapple
  • 本文由 发表于 2020年8月13日 19:57:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/63394673.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定