2.Annotation代替o-r-mapping文件。使用annotation插入Teacher對象 -开发者知识库

2.Annotation代替o-r-mapping文件。使用annotation插入Teacher對象 -开发者知识库,第1张

下載jar文件:

http://sourceforge.net/projects/hibernate/files/hibernate-annotations/

導入jar

hibernate-annotations.jar,ejb3-persistence.jar,hibernate-common-annotations.jar

建立teacher表

create table teacher(id int primary key ,name varchar(20), title varchar(20));

建立Teacher類並使用annotation

package zhx1529.model;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Teacher {
    private String name;
    private int id;
    private String title;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    @Id
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    
}

最佳答案:

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复