lishunli / nutz

Automatically exported from code.google.com/p/nutz
0 stars 0 forks source link

在update时,如果http参数有Date类型为null,会出错 #102

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
java.lang.RuntimeException: Fail to set 'null' by setter 
com.bl.user.pojo.User.'setCreateTime()' because: Fail to cast from 
<java.lang.String> to <java.util.Date> for {} because:
RuntimeException:java.text.ParseException: Unparseable date: ""

nutz  18:23:45
对,调用 update 前,准备 user 时报的错
nutz  18:24:09
HTTP 参数表里, createTime 是什么?
会跑的蜗牛  18:24:27
null值,因为这个是系统自动创建的
会跑的蜗牛  18:24:35
不需要用户手动输入的
会跑的蜗牛  18:24:46
就是创建用户时的时间
nutz  18:24:46
把 setCreateTime 函数内容给我看看 
会跑的蜗牛  18:25:09
就是set 与 get
会跑的蜗牛  18:25:14
一个简单的pojo

Original issue reported on code.google.com by gdun...@gmail.com on 5 Jan 2010 at 10:34

GoogleCodeExporter commented 9 years ago
按照那些出错信息, 输入值为空字符串,不是null哦.

Original comment by wendal1985@gmail.com on 5 Jan 2010 at 2:50

GoogleCodeExporter commented 9 years ago
是的,我在jsp页面放了<input type="hidden" name="createtime"/>

Original comment by gdun...@gmail.com on 6 Jan 2010 at 1:53

GoogleCodeExporter commented 9 years ago
恩, 如何处理好呢? 空字符串忽略掉? 不太好吧...
既然你不传值, 那干脆去掉<input type="hidden" 
name="createtime"/>不就可以了?

Original comment by wendal1985@gmail.com on 6 Jan 2010 at 2:07

GoogleCodeExporter commented 9 years ago
目前是这样处理的,如果将createtime去掉,在update时,就需要�
��以下的方式更新,因为
creatime是not null的。
final User u = user;
            FieldFilter.create(User.class, true).run(new Atom() {
                public void run() {
                    users.dao().update(u);
                }
            });
觉得有点啰嗦,你觉得呢?

Original comment by gdun...@gmail.com on 6 Jan 2010 at 2:33

GoogleCodeExporter commented 9 years ago
按照你的描述,createTime是系统自动创建的

意思是你自己的代码set进去,还是数据库帮你set进去?

Original comment by wendal1985@gmail.com on 6 Jan 2010 at 2:38

GoogleCodeExporter commented 9 years ago
所以,我们需要修改 update 的默认行为
当字段为 null 时不更新,除非显示的通过

FieldFilter.create(User.class, false).run(new Atom() {
    public void run() {
       users.dao().update(u);
    }
});

或者在 Dao 接口增加一个函数 update(T obj, boolean ignoreNullField);

Original comment by zozoh...@gmail.com on 6 Jan 2010 at 8:03

GoogleCodeExporter commented 9 years ago
Fixed in 1.a.26(r811)

增加了 Dao 接口函数  updateIgnoreNull(T obj)

Original comment by zozoh...@gmail.com on 12 Jan 2010 at 8:01

GoogleCodeExporter commented 9 years ago

Original comment by wendal1985@gmail.com on 13 May 2010 at 11:00

GoogleCodeExporter commented 9 years ago
Verified in 1.a.28

Original comment by wendal1985@gmail.com on 15 May 2010 at 8:29