【问题标题】:Spring Roo Date Field with Current Timestamp带有当前时间戳的 Spring Roo 日期字段
【发布时间】:2011-04-05 09:37:43
【问题描述】:

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

CREATE TABLE t (ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP)

如何在 Spring Roo 中实现这一点?找不到来自Roo manual 的提示。

谢谢。

【问题讨论】:

    标签: datetime spring-roo


    【解决方案1】:

    这将通过以下方式创建:

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

    这将添加:

     @Temporal(TemporalType.TIMESTAMP) 
    

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

    进一步注释生成的实体字段
     @Column(name="ts", columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
    

    【讨论】:

      【解决方案2】:

      这可以按照 Simon 的建议完成,但可能值得一试更完整的解决方案。

      查看这个 Spring Roo 时间戳插件。它将“创建”和“更新”时间戳添加到所有标有其注释的实体。 https://github.com/rcaloras/spring-roo-addon-timestamp

      (我创建了它,很高兴回答问题或添加其他功能)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-10-25
        • 2019-07-16
        • 2013-03-10
        • 1970-01-01
        • 1970-01-01
        • 2017-08-08
        • 1970-01-01
        • 2010-12-31
        相关资源
        最近更新 更多