Fun SSH -- heib.pdf (2) --- use annotations to optimize code (optimization of demo1)
In this article, I summarized how to use heib.pdf when learning heib.pdf. In that article, each bean corresponds to an xml file, isn't it a little troublesome? In this article, I would like to outline how to use annotations to optimize the code. before reading the following content, you 'd better read the article mentioned by the Front link.
Most of the steps involved in the previous article do not need to be modified, and step 3 should be changed to the following code:
package com.hibernate;import javax.persistence.Entity;import javax.persistence.Id;@Entitypublic class Student {private int stuId;private String stuName;private String stuSex;private String stuGrade;@Idpublic int getStuId() {return stuId;}public void setStuId(int stuId) {this.stuId = stuId;}public String getStuName() {return stuName;}public void setStuName(String stuName) {this.stuName = stuName;}public String getStuSex() {return stuSex;}public void setStuSex(String stuSex) {this.stuSex = stuSex;}public String getStuGrade() {return stuGrade;}public void setStuGrade(String stuGrade) {this.stuGrade = stuGrade;}}
In the bean class, use annotation @ Entity to indicate that it is an Entity class, and @ Id to indicate that it is the primary key.
Then, cancel Step 4, so that you can use heib.pdf without writing that xml.