SSH framework integration entry landing example -------- the second step Hibernate persistence layer design

introduction

        What we are doing is an introductory practice, so we can just create a table in the database to verify the login!

Create database

        We first create the database sshLogin, and inside the database, create the table User!
Insert picture description here
Insert picture description here

Associate with the database through idea

Insert picture description here
Insert picture description here
        Enter the user, password,         select the database source with the database
Insert picture description here
        configuration Hibernate
Insert picture description here
Insert picture description here
, and create and create a new folder to put our entity classes!
Insert picture description here
        Select the data table and
Insert picture description here
        click OK

Results

Insert picture description here

Let's test the table

We insert a piece of data in the database

Insert picture description here

Configure Hibernate files

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD//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/sshLogin?serverTimezone=UTC</property>
        <property name="connection.username">root</property>
        <property name="connection.password">123</property>
        <!--指定数据库方言-->
        <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
        <!-- DB schema will be updated if needed -->
        <property name="hibernate.hbm2ddl.auto">update</property>
        <!--在控制台显示SQL语句-->
        <property name="show_sql">true</property>
        <!--将SQL脚本中语句格式化在输出-->
        <property name="hibernate.format_sql">true</property>
        <!--罗列所有的持久化类-->
        <mapping class="com.Entity.UserEntity"/>
    </session-factory>
</hibernate-configuration>

The result of running Main.java

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_41827511/article/details/106033700