分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

dljd_(008-010)hibernate_第一个程序

发布时间:2023-09-06 02:25责任编辑:白小东关键词:暂无标签

一、定义实体类

  1.1新建一个java project项目

  1.2新建lib文件夹并导入hibernate项目所必须的外部jar文件

  1.3实体类编写  

package edu.aeon.beans;/** * [说明]:学生实体(bean)类 * @author aeon * */public class Student { ???/**用户id*/ ???private Integer stuId; ???/**用户名*/ ???private String stuName; ???/**用户年龄*/ ???private int stuAge; ???/**用户分数*/ ???private double stuScore; ???/**空构造器*/ ???public Student() { ???????super(); ???} ???/**带惨构造、没有stuId是因为最后这个用户id我们自动生成*/ ???public Student(String stuName, int stuAge, double stuScore) { ???????super(); ???????this.stuName = stuName; ???????this.stuAge = stuAge; ???????this.stuScore = stuScore; ???} ???/**setter/getter*/ ???public Integer getStuId() { ???????return stuId; ???} ???public void setStuId(Integer stuId) { ???????this.stuId = stuId; ???} ???public String getStuName() { ???????return stuName; ???} ???public void setStuName(String stuName) { ???????this.stuName = stuName; ???} ???public int getStuAge() { ???????return stuAge; ???} ???public void setStuAge(int stuAge) { ???????this.stuAge = stuAge; ???} ???public double getStuScore() { ???????return stuScore; ???} ???public void setStuScore(double stuScore) { ???????this.stuScore = stuScore; ???} ???/**重写toString方法*/ ???@Override ???public String toString() { ???????return "Student [stuId=" + stuId + ", stuName=" + stuName + ", stuAge=" + stuAge + ", stuScore=" + stuScore ???????????????+ "]"; ???}}

 1.4映射实体类到数据库表

  dtd头文件可以直接从导入的包中找!  

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC ????"-//Hibernate/Hibernate Mapping DTD 3.0//EN" ???"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"><!-- ????映射文件的作用: ???????1.映射实体类到数据库表 ???????2.映射实体类属性到数据库表字段 --><hibernate-mapping package="edu.aeon.beans.Student"> ???<!-- 1.映射实体类到数据库表 --> ???<class ?table="t_student"> ???<!-- 2.映射实体类属性到数据库表字段 --> ???????<id name="stuId"> ???????????<generator class="native"/> ???????</id> ???<property name="stuName" length="16" column="stu_name" /> ???<property name="stuAge" ?column="stu_age" /> ???<property name="stuScore" length="6" column="t_score" /> ???</class></hibernate-mapping> ???

dljd_(008-010)hibernate_第一个程序

原文地址:https://www.cnblogs.com/aeon/p/10086476.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved