当前位置: 代码迷 >> J2EE >> |javamy|Java根据JavaBean的规则却要写成get,set,这样表字段多了看起来不明了,有什么解决办法?有.NET与Java代码比较 多谢
  详细解决方案

|javamy|Java根据JavaBean的规则却要写成get,set,这样表字段多了看起来不明了,有什么解决办法?有.NET与Java代码比较 多谢

热度:52   发布时间:2016-04-22 00:51:16.0
|javamy|Java根据JavaBean的规则却要写成get,set,这样表字段多了看起来不明了,有什么解决方法?有.NET与Java代码比较 谢谢
我在用.NET对我的Model声明属性的时候用以下方式
当我Model有20个字段的话我也只要写20行,看上去很明了
C# code
public class MyClass{         public string Entity { get; set; }}

但是Java根据JavaBean的规则却要写成
Java code
public class MyClass{         private string entity;    public String getEntity() {        return entity;    }    public void setEntity(String entity) {        this.entity = entity;    }}

这样我的表字段多,我的Model内容就比较长了,看起来不是很明了

Java有没有更好的写法
谢谢

------解决方案--------------------
估计只能看看 Java 1.8 有没有这种特性了。。。
------解决方案--------------------
//注释1
private string entity1;
//注释2
private string entity3;
....

set get 都放在下面,就清晰了

public String getEntity() {
return entity;
}

public void setEntity(String entity) {
this.entity = entity;
}
  相关解决方案