Fun SSH -- heib.pdf (2) --- use annotations to optimize code (optimization of demo1)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.