配置hibernate,Struts。文件

hibernate文件配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory >
<!-- 连接数据库 -->
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.password">123456</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
<property name="hibernate.connection.username">test01</property>
<!-- 数据库方案 -->
<property name="hibernate.default_schema">TEST01</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<!-- 调试 -->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<!-- 自动建表方式 -->
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- 注册映射文件 -->
<mapping resource="com/hanqi/entity/Region.hbm.xml"/>
<mapping resource="com/hanqi/entity/Bank.hbm.xml"/>
</session-factory>
</hibernate-configuration>

  Struts文件配置:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="Struts.action.extension" value="action,do,,"></constant> <package name="index" extends="struts-default"> <action name="testAction" class="com.hanqi.action.testAction" method="testWeb"> <result name="ok">test1.jsp</result>
</action>
<!-- 解耦接口方式 -->
<action name="testActionAware" class="com.hanqi.action.testActionAware" method="testAware">
<result name="ok">test1.jsp</result>
</action> <!-- 以ServletActionConttext方式访问文本资源 -->
<action name="testServletAction" class="com.hanqi.action.testServletAction" method="testServletAction">
<result name="ok" >test1.jsp</result>
</action> <!-- ServletAware接口方式 -->
<action name="testServletAction" class="com.hanqi.action.TestServletAware" method="testServlet">
<result name="ok" >test1.jsp</result>
</action> </package> </struts>

 hibernate配置Dao连接数据库

private Configuration cfg=null;

    private ServiceRegistry sr=null;

    private SessionFactory sf=null;

    private Session se=null;

    private Transaction ts=null;

    public BankDao()
{
//加载配置文件
cfg=new Configuration().configure();
//注册服务
sr=new StandardServiceRegistryBuilder()
.applySettings(cfg.getProperties()).build();
} private void init()
{
sf=cfg.buildSessionFactory(sr); se=sf.openSession(); ts=se.beginTransaction();
} private void destroy()
{
ts.commit(); se.close(); sf.close();
}

 

上一篇:简单MVC实现增删改查


下一篇:【机器学习】--主成分分析PCA降维从初识到应用