model保存后主键id与真实数据不同

张无聊 发布于 2016/05/14 12:39
阅读 186
收藏 0

@JFinal 你好,想跟你请教个问题:

有一个订单对象执行save操作,

boolean save = order.save();
System.out.println("order="+order.toJson());



发现order的主键id与数据库中真实id不同,这种情况是什么原因?

加载中
0
JFinal
JFinal
没看仔细,再多看两眼就好
0
张无聊
张无聊

model的sava方法被我重写过,加入了默认主键生成:


public boolean save() {
    	p("before save="+this.toJson());
        this.set(getTable().getPrimaryKey()[0], getUuidByJdk(true)); 
        p("after save="+this.toJson());
        return _save();
    }
保存对象部分的代码:



p("order0="+order.toJson());
            order.set(Orders.CHANNEL, Orders.CHANNEL_0);
            boolean save = order.save();
            p("order1="+order.toJson());
            response = Orders.dao.getOrderById(order.getId());
            response.setCode(save ? Code.SUCCESS : Code.FAIL).setMessage(save ? "save success" : "save failed");            
            renderJson(response);
其中打印信息如下:



before save={"amount":"11","app":"1234567890","channel":"balance","currency":"cny","idcard":"120702196009022114","livemode":0,"order_no":"123","org_id":"1234567890","remarks":"this is the test 05","suminsured":"10","time_expire":"2016-05-14 12:22:25"}
after save={"amount":"11","app":"1234567890","channel":"balance","currency":"cny","id":"ba1bbf94f87749c68acc516c8c0ee7c0","idcard":"120702196009022114","livemode":0,"order_no":"123","org_id":"1234567890","remarks":"this is the test 05","suminsured":"10","time_expire":"2016-05-14 12:22:25"}
order1={"amount":"11","app":"1234567890","channel":"balance","currency":"cny","id":"cb72c9f7e3364808aba7609aaeb76f3c","idcard":"120702196009022114","livemode":0,"order_no":"123","org_id":"1234567890","remarks":"this is the test 05","suminsured":"10","time_expire":"2016-05-14 12:22:25"}
可以看到after save时的id的值与order1时的id 的值不同


0
tinshen
tinshen

_save()是什么鬼?

返回顶部
顶部