我们正在使用自动计算机来创建我们的pojo对象,以在RPC-calls中使用。POJO具有默认值或其他类初始化的建议方法是什么?
例如
public interface SamplePojo {
// should default to 5
int getSampleProperty();
void setSampleProperty(int sampleProperty);
}
public interface ModelFactory extends AutoBeanFactory {
AutoBean<SamplePojo> getSamplePojo();
}
和SamplePoJo具有一个int属性,我们始终希望默认为5。
AutoBeans应视为低级,直接映射到JSON。考虑到这一点,您不希望 getSampleProperty()
to be 5,您宁愿检测到属性的特定值,在这种情况下使用 5。<<<<<<<<<<
因此,如果0
(int
的默认值)不是该属性的可接受值,则只需"如果属性为0",则只需"使用5"即可。否则,将返回类型更改为Integer
,并且"如果属性为null
"。
这可以工作吗?
public interface SamplePojo {
// should default to 5
int getSampleProperty();
void setSampleProperty(int sampleProperty);
}
public class SamplePojoImpl implements SamplePojo{
private int sampleProperty = 5
// getters/setters
int getSampleProperty(){ return sampleProperty;}
void setSampleProperty(int sampleProperty){this.sampleProperty = sampleProperty;}
}
public interface ModelFactory extends AutoBeanFactory {
AutoBean<SamplePojo> getSamplePojo(SamplePojoImpl samplePojo );
}