java - Qu'est-ce qu'un JavaBean exactement

Mots clés : javadependency-injectioninversion-of-controljavabeansserializablejava

meilleur 2 Réponses java - Qu'est-ce qu'un JavaBean exactement

vote vote

91

@Entity public class Employee implements Serializable{     @Id    private int id;    private String name;       private int salary;       public Employee() {}     public Employee(String name, int salary) {       this.name = name;       this.salary = salary;    }    public int getId() {       return id;    }    public void setId( int id ) {       this.id = id;    }    public String getName() {       return name;    }    public void setName( String name ) {       this.name = name;    }    public int getSalary() {       return salary;    }    public void setSalary( int salary ) {       this.salary = salary;    } } 
vote vote

88

/** 1. import java.io.Serializable */ public class User implements java.io.Serializable {     /** 2. private fields */     private int id;     private String name;      /** 3. Constructor */     public User() {     }     public User(int id, String name) {         this.id = id;         this.name = name;     }      /** 4. getter/setter */     // getter     public int getId() {         return id;     }     public String getName() {         return name;     }     // setter     public void setId(int id) {         this.id = id;     }     public void setName(String name) {         this.name = name;     } } 

Questions similaires