框架搭建(五)单独配置hibernate

1.导入dtd文件约束,自行百度查,一抓一大把

2.创建一个包,导入我们需要的实体类&orm元数据

例如:

2.配置主配置文件,hibernate.cfg.xml

	    <!-- 数据库驱动 -->
		<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
		 <!-- 数据库url -->
		<property name="hibernate.connection.url">jdbc:mysql:///数据库名字</property>
		 <!-- 数据库连接用户名 -->
		<property name="hibernate.connection.username">账号</property>
		 <!-- 数据库连接密码 -->
		<property name="hibernate.connection.password">密码</property>
	
		<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
		

可选配置


		<!-- 将hibernate生成的sql语句打印到控制台 -->
		<property name="hibernate.show_sql">true</property>
		<!-- 将hibernate生成的sql语句格式化(语法缩进) -->
		<property name="hibernate.format_sql">true</property>
	
		<property name="hibernate.hbm2ddl.auto">update</property>
		

引入实体配置文件


		<mapping resource="domain/User.hbm.xml" /> 
		<mapping resource="domain/Role.hbm.xml" /> 
		<mapping resource="domain/Customer.hbm.xml" /> 
		<mapping resource="domain/LinkMan.hbm.xml" /> 
		

配置完成

猜你喜欢

转载自blog.csdn.net/qq_41319352/article/details/81237465