Hibernate(2)_Hibernate 环境搭建

本系列博客汇总在这里:Hibernate 汇总


源码工程文件为:

一、文件下载

官网下载地址 :http://hibernate.org/orm/downloads/

本教程使用的:点击下载,提取码:bszm。
在这里插入图片描述
在这里插入图片描述
官方文档:点击下载,提取码:qkby。
在这里插入图片描述

二、搭建环境

1、建立一个 java 项目

2、导包

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

3、创建 hibernate.cfg.xml

默认位置在 classpath 下,默认名称 hibernate.cfg.xml,可以随便起名 xxx.xml,建议使用hibernate.cfg.xml。

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <!-- 数据库连接设置 -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/hiber01</property>
        <property name="connection.username">root</property>
        <property name="connection.password">root</property>

        <!-- 设置数据库连接池的初始化连接数 -->
        <property name="connection.pool_size">1</property>
        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
        <property name="show_sql">true</property>
        <mapping resource=""/>
    </session-factory>
</hibernate-configuration>

4、创建实体类(model)

package com.wyx.hiber.model;

import java.util.Date;

public class User
{

	private String userId;

	private String uname;

	private Integer gender;

	private Date birthday;

	public String getUserId()
	{
		return userId;
	}

	public void setUserId(String userId)
	{
		this.userId = userId;
	}

	public String getUname()
	{
		return uname;
	}

	public void setUname(String uname)
	{
		this.uname = uname;
	}

	public Integer getGender()
	{
		return gender;
	}

	public void setGender(Integer gender)
	{
		this.gender = gender;
	}

	public Date getBirthday()
	{
		return birthday;
	}

	public void setBirthday(Date birthday)
	{
		this.birthday = birthday;
	}

}

如有错误,欢迎指正!

发布了448 篇原创文章 · 获赞 210 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/qq_36260974/article/details/104099722