<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 千里冰封 閱讀(981) 評論(0)  編輯  收藏 所屬分類: JAVAEE
    主站蜘蛛池模板: 亚洲国产a级视频| 国产a不卡片精品免费观看| 亚洲午夜久久久久久噜噜噜| 亚洲AV无码一区二区三区牲色| 欧美三级在线电影免费| 亚洲AV成人无码天堂| 免费毛片在线看片免费丝瓜视频| 色老板亚洲视频免在线观| 女人18毛片水真多免费播放| 亚洲欧美熟妇综合久久久久| 日韩免费高清视频| 老司机精品视频免费| 亚洲人成网站观看在线播放 | 波多野结衣亚洲一级| 国产一卡2卡3卡4卡无卡免费视频| 亚洲永久在线观看| 精品免费久久久久久成人影院| 18禁亚洲深夜福利人口| 亚洲精品成人区在线观看| 久久精品国产影库免费看| 久久久亚洲欧洲日产国码aⅴ| 久久久久久久免费视频| 美国毛片亚洲社区在线观看| 亚洲一区二区三区免费| 无码日韩精品一区二区三区免费 | 亚洲免费网站观看视频| 色婷婷亚洲一区二区三区| 中文字幕中韩乱码亚洲大片| 97视频免费观看2区| 亚洲色精品VR一区区三区| 亚洲成人高清在线| 久久亚洲免费视频| 伊人久久亚洲综合影院首页| 亚洲av中文无码| 91大神免费观看| 国产精品无码亚洲一区二区三区| 亚洲精品乱码久久久久66| 国产91色综合久久免费分享| 曰批免费视频播放在线看片二| 亚洲AV一宅男色影视| 午夜免费不卡毛片完整版|