如何告诉Play Framework 2和Ebean保存空字段? [英] How do I tell Play Framework 2 and Ebean to save null fields?

查看:102
本文介绍了如何告诉Play Framework 2和Ebean保存空字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Play Framework 2和Ebean.当用户提交表单以编辑数据库中的现有对象时,它不会保存空值.我想这是为了防止覆盖非null形式的字段.但是,如果需要,我如何让他们将表单中的字段设置为null?

I'm using Play Framework 2 and Ebean. When a user submits a form to edit an existing object in the database, it doesn't save null values. I guess this is to prevent overwriting fields that aren't in the form with null. But how can I let them set fields in the form to null if they need to?

例如,用户编辑Event对象. Event.date是1/1/13.用户将表单中的Event.date字段设置为空,然后提交表单.在调试器中检查Event.date会显示其值为null.我保存了Event.如果我查看数据库中的Event,它的值仍然是1/1/13.

For example, the user edits an Event object. Event.date is 1/1/13. The user sets the Event.date field in the form to empty and submits the form. Inspecting Event.date in the debugger shows its value is null. I save the Event. If I look at the Event in the database, its value is still 1/1/13.

似乎有一种解决方法.唯一的问题是它不适用于嵌套实体.有什么解决办法吗?

It seems there is a method for this. The only problem is it doesn't work on nested entities. Any solutions for this?

update(Object bean,Set<String> properties)

推荐答案

application.conf文件旁边创建一个ebean.properties文件,并将以下行添加到其中:

Create an ebean.properties file right next to the application.conf file and add this line to it:

ebean.defaultUpdateNullProperties=true

这篇关于如何告诉Play Framework 2和Ebean保存空字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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