• 配置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();
        }

     

  • 相关阅读:
    团队作业—第二阶段08
    团队作业—第二阶段07
    java--Map使用实现模拟斗地主洗牌发牌
    课程作业08 MVC框架具体使用
    课程作业 MVC框架
    课堂作业06_23种设计模式
    课堂作业05 《6种质量属性战术》
    课堂作业04
    课堂作业03
    架构漫谈阅读笔记
  • 原文地址:https://www.cnblogs.com/tfl-511/p/6116227.html
Copyright © 2020-2023  润新知