玩!框架CRUD模块:添加默认值并更改日期格式? [英] Play! framework CRUD module: adding default values and change date format?

查看:130
本文介绍了玩!框架CRUD模块:添加默认值并更改日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Play!框架CRUD模块,但我不能弄清楚:我的数据库表有一个创建的字段,这基本上是创建行的时间。我不希望我的用户设置这个,我想在后端做,只需添加当前的时间。我不知道如何做到这一点。

I'm using Play! frameworks CRUD module but I can't figure something out: my database table has a created field which is basically the time that a row was created. I don't want my user to set this, I want to do it in the backend, simply add the current time. I can't figure out how to do this though.

我已经使用 @Hidden 显然现在我不能创建新的行,因为它的值只是没有设置。那么我该怎么做?

I have made the field invisible using @Hidden but obviously now I can't create new rows because it's value simply isn't set. So where do I do this?

另有一个问题我的表还有一个名为的列发布是另一个时间戳。 CRUD窗体中此字段的当前格式为yyyy-MM-dd。我想要指定一个日期,并不能弄清楚如何..

And another question I have: my table also has a column called publish which is another timestamp. The current format for this field in the CRUD form is yyyy-MM-dd. I would like the specify a date as well, and can't figure out how..

有人可以帮助吗?

推荐答案

可以使用自定义字段渲染在CRUD模板中显示格式化或使用任何您想要的控件的值(即:日期的jquery日期选择器)。

you can use custom field rendering in CRUD templates to display the values formatted or using any control you want (i.e.: a jquery date picker for dates).

隐藏值和分配一个默认值,首先通过删除该字段从编辑/空白形式的CRUD中删除该值。然后从实体中覆盖_save()方法(注意初始_,你想要_save(),而不是save()),并在代码中设置你想要的值,然后再调用super._save()。像这样:

To hide a value and assign a default value, first of all remove the value from the edit/blank forms of CRUD by removing the field. Then override the _save() method from the entity (be careful with the initial _, you want the _save(), not save()) and set in the code the values you want before calling super._save(). Like this:

/* Return value may differ */
public void _save() {
   current = new Date();
   super._save();
}

这篇关于玩!框架CRUD模块:添加默认值并更改日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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