<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    千里冰封
    JAVA 濃香四溢
    posts - 151,comments - 2801,trackbacks - 0

    以前看到一本書上寫的,有關定義實體BEAN的一些細節,直到今天才知道其中的差別

    代碼1:

    /*   
     * Test.java   
     *   
     * Created on 2006年12月15日, 上午12:06   
     *   
     * To change this template, choose Tools | Template Manager   
     * and open the template in the editor.   
     
    */   
       
    package com.hadeslee.entity;    
       
    import java.io.Serializable;    
    import javax.persistence.Entity;    
    import javax.persistence.GeneratedValue;    
    import javax.persistence.GenerationType;    
    import javax.persistence.Id;    
       
    /**   
     * Entity class Test   
     *    
     * 
    @author lbf   
     
    */   
    @Entity   
    public class Test implements Serializable {    
        
    private Long id;    
        
    private String name,sex,age;    
        
    private int idCard;    
        
    /** Creates a new instance of Test */   
        
    public Test() {    
        }    
       
        
    /**   
         * Gets the id of this Test.   
         * 
    @return the id   
         
    */   
        @Id   
        @GeneratedValue(strategy 
    = GenerationType.AUTO)    
        
    public Long getId() {    
            
    return this.id;    
        }    
       
        
    /**   
         * Sets the id of this Test to the specified value.   
         * 
    @param id the new id   
         
    */   
        
    public void setId(Long id) {    
            
    this.id = id;    
        }    
        
    public void setNameID(int ids){    
            
    this.idCard=ids;    
        }    
        
    public int getNameID(){    
            
    return idCard;    
        }    
       
        
    /**   
         * Returns a hash code value for the object.  This implementation computes    
         * a hash code value based on the id fields in this object.   
         * 
    @return a hash code value for this object.   
         
    */   
        @Override   
        
    public int hashCode() {    
            
    int hash = 0;    
            hash 
    += (this.id != null ? this.id.hashCode() : 0);    
            
    return hash;    
        }    
       
        
    /**   
         * Determines whether another object is equal to this Test.  The result is    
         * true if and only if the argument is not null and is a Test object that    
         * has the same id field values as this object.   
         * 
    @param object the reference object with which to compare   
         * 
    @return true if this object is the same as the argument;   
         * false otherwise.   
         
    */   
        @Override   
        
    public boolean equals(Object object) {    
            
    // TODO: Warning - this method won't work in the case the id fields are not set    
            if (!(object instanceof Test)) {    
                
    return false;    
            }    
            Test other 
    = (Test)object;    
            
    if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false;    
            
    return true;    
        }    
       
        
    /**   
         * Returns a string representation of the object.  This implementation constructs    
         * that representation based on the id fields.   
         * 
    @return a string representation of the object.   
         
    */   
        @Override   
        
    public String toString() {    
            
    return "com.hadeslee.entity.Test[id=" + id + "]";    
        }    
       
        
    public String getName() {    
            
    return name;    
        }    
       
        
    public void setName(String name) {    
            
    this.name = name;    
        }    
       
        
    public String getSex() {    
            
    return sex;    
        }    
       
        
    public void setSex(String sex) {    
            
    this.sex = sex;    
        }    
       
        
    public String getAge() {    
            
    return age;    
        }    
       
        
    public void setAge(String age) {    
            
    this.age = age;    
        }    
            
    }    

    代碼2:

     

    /*   
     * Test.java   
     *   
     * Created on 2006年12月15日, 上午12:06   
     *   
     * To change this template, choose Tools | Template Manager   
     * and open the template in the editor.   
     
    */   
       
    package com.hadeslee.entity;    
       
    import java.io.Serializable;    
    import javax.persistence.Entity;    
    import javax.persistence.GeneratedValue;    
    import javax.persistence.GenerationType;    
    import javax.persistence.Id;    
       
    /**   
     * Entity class Test   
     *    
     * 
    @author lbf   
     
    */   
    @Entity   
    public class Test implements Serializable {    
        @Id   
        @GeneratedValue(strategy 
    = GenerationType.AUTO)    
        
    private Long id;    
        
    private String name,sex,age;    
        
    private int idCard;    
        
    /** Creates a new instance of Test */   
        
    public Test() {    
        }    
       
        
    /**   
         * Gets the id of this Test.   
         * 
    @return the id   
         
    */   
           
        
    public Long getId() {    
            
    return this.id;    
        }    
       
        
    /**   
         * Sets the id of this Test to the specified value.   
         * 
    @param id the new id   
         
    */   
        
    public void setId(Long id) {    
            
    this.id = id;    
        }    
        
    public void setNameID(int ids){    
            
    this.idCard=ids;    
        }    
        
    public int getNameID(){    
            
    return idCard;    
        }    
       
        
    /**   
         * Returns a hash code value for the object.  This implementation computes    
         * a hash code value based on the id fields in this object.   
         * 
    @return a hash code value for this object.   
         
    */   
        @Override   
        
    public int hashCode() {    
            
    int hash = 0;    
            hash 
    += (this.id != null ? this.id.hashCode() : 0);    
            
    return hash;    
        }    
       
        
    /**   
         * Determines whether another object is equal to this Test.  The result is    
         * true if and only if the argument is not null and is a Test object that    
         * has the same id field values as this object.   
         * 
    @param object the reference object with which to compare   
         * 
    @return true if this object is the same as the argument;   
         * false otherwise.   
         
    */   
        @Override   
        
    public boolean equals(Object object) {    
            
    // TODO: Warning - this method won't work in the case the id fields are not set    
            if (!(object instanceof Test)) {    
                
    return false;    
            }    
            Test other 
    = (Test)object;    
            
    if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) return false;    
            
    return true;    
        }    
       
        
    /**   
         * Returns a string representation of the object.  This implementation constructs    
         * that representation based on the id fields.   
         * 
    @return a string representation of the object.   
         
    */   
        @Override   
        
    public String toString() {    
            
    return "com.hadeslee.entity.Test[id=" + id + "]";    
        }    
       
        
    public String getName() {    
            
    return name;    
        }    
       
        
    public void setName(String name) {    
            
    this.name = name;    
        }    
       
        
    public String getSex() {    
            
    return sex;    
        }    
       
        
    public void setSex(String sex) {    
            
    this.sex = sex;    
        }    
       
        
    public String getAge() {    
            
    return age;    
        }    
       
        
    public void setAge(String age) {    
            
    this.age = age;    
        }    
            
    }    


    代碼1和代碼2唯一的差別就是@Id的注釋地方不同了

    同樣是注釋主鍵,當在直接用在變量上注釋時,如果其它的成員變量沒有指定名字,則數據庫生成的表的各列名字將以定義的成員變量的變量名為準

    當用在getter方法注釋時,則數據庫生成的表的各列名字將取getXXXX的XXXX名字,將不再取定義的成員變量名

    像上面的例子中,代碼1會有IdCard這一列,則代碼2取而代之的將是NameID這一列.這看上去是一個小小的差別,但是了解了終究是好事.呵呵.終于懂清楚在get上注釋和直接在成員變量上注釋的差別了,一般來說是不會有什么差別的,一般標準 的JAVABEAN都是成員變量名和getter,setter簽名一樣的.




    盡管千里冰封
    依然擁有晴空

    你我共同品味JAVA的濃香.
    posted on 2007-09-11 15:45 千里冰封 閱讀(982) 評論(0)  編輯  收藏 所屬分類: JAVAEE
    主站蜘蛛池模板: 狠狠亚洲婷婷综合色香五月排名| 妞干网免费观看视频| 亚洲一区二区高清| 免费一级毛suv好看的国产网站| 国产在线19禁免费观看国产| 亚洲精品无码久久久久A片苍井空| 国产成人免费爽爽爽视频| 亚洲国产乱码最新视频| 毛片a级毛片免费观看品善网| 亚洲免费观看网站| 国产三级在线观看免费| 亚洲av永久无码精品秋霞电影秋 | 国产亚洲精品无码拍拍拍色欲| 一级午夜免费视频| 国产亚洲一区二区三区在线| 亚洲精品免费视频| youjizz亚洲| 国产精品国产午夜免费福利看 | 又粗又大又硬又爽的免费视频| 色妞www精品视频免费看| 三上悠亚亚洲一区高清| 一级特黄aa毛片免费观看| 亚洲国产日韩在线人成下载| 在线免费不卡视频| 一级做a毛片免费视频| 亚洲AV无码乱码在线观看裸奔| 很黄很黄的网站免费的| 欧洲亚洲综合一区二区三区| 亚洲乱亚洲乱妇无码麻豆| 国产91免费视频| 男女啪啪免费体验区| 久久夜色精品国产嚕嚕亚洲av| 97人妻无码一区二区精品免费| 男女超爽视频免费播放| 婷婷亚洲综合五月天小说| 精品久久久久久久免费人妻| 日本免费A级毛一片| 亚洲私人无码综合久久网| 亚洲色偷拍另类无码专区| 成年女人毛片免费观看97| 黄色短视频免费看|