javax.persistence.Temporal @Temporal 使用过程中的释疑

 最近自己在使用JPA过程中接连遇到一些问题,决定深入研究一下。

以下为@Temporal标注的用法:

      

       (A) 如果在某类中有Date类型的属性,数据库中存储可能是'yyyy-MM-dd hh:MM:ss'要在查询时获得年月日,在该属性上标               注 @Temporal(TemporalType.DATE) 会得到形如'yyyy-MM-dd' 格式的日期。

       (B)如果在某类中有Date类型的属性,数据库中存储可能是'yyyy-MM-dd hh:MM:ss'要获得时分秒,在该属性上标注                    @Temporal(TemporalType.TIME) 会得到形如''yyyy-MM-dd HH:MM:SS' 格式的日期。

       (C)如果在某类中有Date类型的属性,数据库中存储可能是'yyyy-MM-dd hh:MM:ss'要获得'是'yyyy-MM-dd hh:MM:ss',在             该属性上标注 @Temporal(TemporalType.TIMESTAMP) 会得到形如''yyyy-MM-dd HH:MM:SS' 格式的日期

猜你喜欢

转载自blog.csdn.net/Monster_WangXiaotu/article/details/79011044