生成对象

时间:2015-07-28 11:35:03

标签: java eclipse plugins

我有一个包含多个set和get的对象。例如:

MettreAJourPersonne entree = new MettreAJourPersonne();
        entree.setLnPEO("CHANTRAIT");
        entree.setLpPEO("THERESE");
        entree.setLnPEOPNY("");
        entree.setCdPEOSEX("F");
        entree.setCdPEOSMT("C");
        entree.set .........

如何自动生成对象主菜单的所有get / set?

THX

编辑:

我的对象MettreAJourPersonne:

public class MettreAJourPersonne {

private String lnPEO;
private String lpPEO;
private String lnPEOPNY;
private String cdPEOSEX;
private String cdPEOSMT;
private String ayPEOFIS;
private String alPEOCOUCMP;
private String alPEOCOUBAT;
private String alPEOCOURUE;
private String alPEOCARCMP;
private String acPEOCOU;
private String alPEOCOUCMN;
private String ayPEOCOU;
.........(more elements).....



/**
 * @return the lnPEO
 */
public String getLnPEO() {
    return lnPEO;
}

/**
 * @param lnPEO
 *            the lnPEO to set
 */
public void setLnPEO(String lnPEO) {
    this.lnPEO = lnPEO;
}

/**
 * @return the lpPEO
 */
public String getLpPEO() {
    return lpPEO;
}

/**
 * @param lpPEO
 *            the lpPEO to set
 */
public void setLpPEO(String lpPEO) {
    this.lpPEO = lpPEO;
}

/**
 * @return the lnPEOPNY
 */
public String getLnPEOPNY() {
    return lnPEOPNY;
}

/**
 * @param lnPEOPNY
 *            the lnPEOPNY to set
 */
public void setLnPEOPNY(String lnPEOPNY) {
    this.lnPEOPNY = lnPEOPNY;
}

/**
 * @return the cdPEOSEX
 */
public String getCdPEOSEX() {
    return cdPEOSEX;
}

/**
 * @param cdPEOSEX
 *            the cdPEOSEX to set
 */
public void setCdPEOSEX(String cdPEOSEX) {
    this.cdPEOSEX = cdPEOSEX;
}

/**
 * @return the cdPEOSMT
 */
public String getCdPEOSMT() {
    return cdPEOSMT;
}

/**
 * @param cdPEOSMT
 *            the cdPEOSMT to set
 */
public void setCdPEOSMT(String cdPEOSMT) {
    this.cdPEOSMT = cdPEOSMT;
}

/**
 * @return the ayPEOFIS
 */
public String getAyPEOFIS() {
    return ayPEOFIS;
}

/**
 * @param ayPEOFIS
 *            the ayPEOFIS to set
 */
public void setAyPEOFIS(String ayPEOFIS) {
    this.ayPEOFIS = ayPEOFIS;
}

/**
 * @return the alPEOCOUCMP
 */
public String getAlPEOCOUCMP() {
    return alPEOCOUCMP;
}

/**
 * @param alPEOCOUCMP
 *            the alPEOCOUCMP to set
 */
public void setAlPEOCOUCMP(String alPEOCOUCMP) {
    this.alPEOCOUCMP = alPEOCOUCMP;
}

/**
 * @return the alPEOCOUBAT
 */
public String getAlPEOCOUBAT() {
    return alPEOCOUBAT;
}

/**
 * @param alPEOCOUBAT
 *            the alPEOCOUBAT to set
 */
public void setAlPEOCOUBAT(String alPEOCOUBAT) {
    this.alPEOCOUBAT = alPEOCOUBAT;
}

/**
 * @return the alPEOCOURUE
 */
public String getAlPEOCOURUE() {
    return alPEOCOURUE;
}

/**
 * @param alPEOCOURUE
 *            the alPEOCOURUE to set
 */
public void setAlPEOCOURUE(String alPEOCOURUE) {
    this.alPEOCOURUE = alPEOCOURUE;
}

/**
 * @return the alPEOCARCMP
 */
public String getAlPEOCARCMP() {
    return alPEOCARCMP;
}

/**
 * @param alPEOCARCMP
 *            the alPEOCARCMP to set
 */
public void setAlPEOCARCMP(String alPEOCARCMP) {
    this.alPEOCARCMP = alPEOCARCMP;
}

/**
 * @return the acPEOCOU
 */
public String getAcPEOCOU() {
    return acPEOCOU;
}

/**
 * @param acPEOCOU
 *            the acPEOCOU to set
 */
public void setAcPEOCOU(String acPEOCOU) {
    this.acPEOCOU = acPEOCOU;
}

/**
 * @return the alPEOCOUCMN
 */
public String getAlPEOCOUCMN() {
    return alPEOCOUCMN;
}

/**
 * @param alPEOCOUCMN
 *            the alPEOCOUCMN to set
 */
public void setAlPEOCOUCMN(String alPEOCOUCMN) {
    this.alPEOCOUCMN = alPEOCOUCMN;
}

/**
 * @return the ayPEOCOU
 */
public String getAyPEOCOU() {
    return ayPEOCOU;
}

/**
 * @param ayPEOCOU
 *            the ayPEOCOU to set
 */
public void setAyPEOCOU(String ayPEOCOU) {
    this.ayPEOCOU = ayPEOCOU;
}
............(more get and set)

现在,我想在其他类中使用对象MettreAJourPersonne(),并自动生成其他类中的所有集合

MettreAJourPersonne entree = new MettreAJourPersonne();
            entree.setLnPEO("CHANTRAIT");
            entree.setLpPEO("THERESE");
            entree.setLnPEOPNY("");
            entree.setCdPEOSEX("F");
            entree.setCdPEOSMT("C");
            entree.set .........

现在,我必须(手动)编写对方法集的每次调用:example

entree.setLnPeo("A")
entree.setLpPeo("B")

...

4 个答案:

答案 0 :(得分:0)

在eclipse中打开MettreAJourPersonne - 来源,按ALT-SHIFT-S,然后按Generate Getter / Setter并配置您的愿望。

答案 1 :(得分:0)

ALT+SHIFT+s然后按press r, 选择你想要创建setter和getter方法的变量。

答案 2 :(得分:0)

右键单击eclipse编码窗口 - >选择“source”选项 - >单击Generate setter and getter选项。您可以轻松生成所有属性setter getter方法。

答案 3 :(得分:0)

您可以使用插件 lombok 无需编写set / get方法。注释适用于所有事物。只需添加以下依赖项:

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.16.4</version>
</dependency>

使用如下: import lombok.Getter; import lombok.Setter;

/**
 *
 * @author devb
 */
@Getter
@Setter
public class Person {

    private String name;
}

测试另一个类是:

/**
 *
 * @author devb
 */
public class AnnotationSetGetTest {

    public static void main(String[] args) {
        Person person = new Person();
        person.setName("Bhuwan");
        System.out.println(person.getName());
    }
}

输出:

Bhuwan

查看更多信息:Lombok