英文:
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
java.time.Instant、java.time.LocalDateTime、java.time.OffsetDateTime和java.time.ZonedDateTime。
- 您还可以使用过时的
java.util.Date(请参见此处):
@Column(name = "`timestamp`")
@Temporal(TemporalType.TIMESTAMP)
private Date timestamp;
但第一种方法更加推荐。
英文:
The list of standard basic types you can find here.
- You can map
TIMESTAMPto the following Java 8 types:
java.time.Instant, java.time.LocalDateTime, java.time.OffsetDateTime and java.time.ZonedDateTime.
- 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论