之前开发都是使用xml配置来开发项目,开发起来特别繁琐

大家会发现通过注解大大简化了我们开发流程,使我们从繁琐的XML配置中解放出来。

第一步:新建一个javaweb项目。并将hibernate需要的相关jar包导入。

 

第二步: 使用annotation需要额外增加3个jar包:

◦ hibernate-annotations.jar

◦ ejb3-persistence.jar

◦ hibernate-commons-annotations.jar

 

第三步:新建一个pojo并增加注解:

 1 package com.qcf.pox;
 2 
 3 import java.util.Date;
 4 
 5 import javax.persistence.Entity;
 6 import javax.persistence.GeneratedValue;
 7 import javax.persistence.GenerationType;
 8 import javax.persistence.Id;
 9 
10 @Entity 
11 public class Student {
12     
13     @Id
14     @GeneratedValue(strategy=GenerationType.AUTO)//代表主键的生成策略
15     private int stuno;
16     private String stuname;
17     private Date birthday;
18     public int getStuno() {
19         return stuno;
20     }
21     public void setStuno(int stuno) {
22         this.stuno = stuno;
23     }
24     public String getStuname() {
25         return stuname;
26     }
27     public void setStuname(String stuname) {
28         this.stuname = stuname;
29     }
30     public Date getBirthday() {
31         return birthday;
32     }
33     public void setBirthday(Date birthday) {
34         this.birthday = birthday;
35     }
36     public Student() {
37         super();
38     }
39     public Student(int stuno, String stuname, Date birthday) {
40         super();
41         this.stuno = stuno;
42         this.stuname = stuname;
43         this.birthday = birthday;
44     }
45     
46 }
View Code

相关文章:

  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
  • 2022-01-29
  • 2021-06-02
  • 2022-12-23
  • 2021-10-26
  • 2021-10-10
猜你喜欢
  • 2021-04-09
  • 2021-11-22
  • 2022-12-23
相关资源
相似解决方案