1....maven下的pom.xml配置文件:

pom.xml

2....resources下的META-INF下的persistence.xml(注意:此为分层切文件名字默认,不许更改

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
 3     <!--配置持久化单元  在配置文件中至少有一个
 4        name  持久化单元的名称
 5        transaction-type   事物类型
 6        RESOURCE_LOCAL   单数据库的事物
 7        JTA  分布式事物  跨数据的事物   多个数据库的事物
 8     -->
 9     <persistence-unit name="mysqlAccount" transaction-type="RESOURCE_LOCAL">
10         <properties>
11             <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
12             <property name="javax.persistence.jdbc.user" value="root"/>
13             <property name="javax.persistence.jdbc.password" value="wsc"/>
14             <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/shop"/>
15             
16             <!--配置hibernate的属性
17             是否在控制台输出SQL语句-->
18             <property name="hibernate.show_sql" value="true"/>
19             <!--sql语句是否格式化-->
20             <property name="hibernate.format_sql" value="true"/>
21 
22             <!--是否自动创建数据库表
23               value 可选值   create  update   none
24               create  程序自动创建数据库表  如果表存在  先删除后创建
25               update  程序自动创建数据库表  如果表存在  不创建
26               none   不会创建
27             -->
28             <property name="hibernate.hbm2ddl.auto" value="create"/>
29        </properties>
30 
31 
32    </persistence-unit>
33 </persistence>
persistence.xml

相关文章:

  • 2022-12-23
  • 2021-10-04
  • 2021-05-28
猜你喜欢
  • 2022-01-07
  • 2021-12-02
  • 2022-12-23
  • 2022-01-15
  • 2021-07-28
  • 2022-02-23
  • 2022-01-02
相关资源
相似解决方案