GWT Autobean设置创建的界面的初始值 [英] GWT Autobean set initial value of created interface

查看:152
本文介绍了GWT Autobean设置创建的界面的初始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用AutoBeans来创建用于RPC-Calls的Pojo对象。对于Pojo有一个默认值或其他类初始化的建议方法是什么?



例如

 public interface SamplePojo {
//应该默认为5
int getSampleProperty();
void setSampleProperty(int sampleProperty);
}


public interface ModelFactory扩展AutoBeanFactory {
AutoBean< SamplePojo> getSamplePojo();
}

而SamplePojo有一个int属性,我们总是希望默认为5。 / p>

解决方案

AutoBeans应该被视为低级别,直接映射到/从JSON映射。考虑到这一点,您不希望 getSampleProperty() be 5,您宁愿要检测属性是否缺少特定值在这种情况下使用 5。



因此,如果 0 (默认值 int )不是该属性的可接受值,那么只需如果该属性为0,则使用5。否则,请将返回类型更改为 Integer ,如果属性 null ,则使用5。 b $ b

We are using AutoBeans to create our Pojo objects for use in RPC-Calls. What is the recommended approach for the Pojo to have a default value or other class initialization?

For example

 public interface SamplePojo {
        // should default to 5
        int getSampleProperty();
        void setSampleProperty(int sampleProperty);
    }


    public interface ModelFactory extends AutoBeanFactory {
        AutoBean<SamplePojo> getSamplePojo();   
    }

And SamplePojo has a int property that we always want to default to 5.

解决方案

AutoBeans should be seen as low-level, mapping straight to/from JSON. With that in mind, you don't want getSampleProperty() to be 5, you rather want to detect the absence of specific value for the property and use 5 in that case.

So, if 0 (the default value of an int) is not an acceptable value for the property, then simply "use 5 if the property is 0". Otherwise, change the return type to Integer and "use 5 if the property is null".

这篇关于GWT Autobean设置创建的界面的初始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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