Spring Roo日期字段与当前时间戳 [英] Spring Roo Date Field with Current Timestamp

查看:117
本文介绍了Spring Roo日期字段与当前时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数数据库允许具有当前时间戳的字段(作为创建时间戳),例如在MySQL中:

  CREATE TABLE t(ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP)

如何在Spring Roo中实现?无法从 Roo手册



谢谢。

解决方案

 字段日期--fieldName ts --type java.util.Date --persistenceType JPA_TIMESTAMP 

这将添加:

  Temporal(TemporalType.TIMESTAMP)

到字段,这应该导致自动生成器创建一个TIMESTAMP领域。如果你想要更多的控制,你可以随时用

  @Column(name =ts,columnDefinition =TIMESTAMP DEFAULT CURRENT_TIMESTAMP)


Most databases allow to have field with current timestamp (act as creation timestamp), for example in MySQL:

CREATE TABLE t (ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP)

How to achieve this in Spring Roo? Can't find hint from Roo manual.

Thanks.

解决方案

This would be created with:

field date --fieldName ts --type java.util.Date --persistenceType JPA_TIMESTAMP

This will add:

 @Temporal(TemporalType.TIMESTAMP) 

to the field, which should cause the auto-generator to create a TIMESTAMP field. If you want more control, you can always annotate the generated entity field further with

 @Column(name="ts", columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP")

这篇关于Spring Roo日期字段与当前时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆