ssh配置文件模板

来源:互联网 发布:淘宝钻展在哪里 编辑:程序博客网 时间:2024/04/28 19:45

hibernate配置

hibernate.cfg.xml

<?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="myeclipse.connection.profile">mysql</property>
<property name="connection.url">jdbc:mysql://127.0.0.1:3306/yan</property>
<property name="connection.username">root</property>
<property name="connection.password">yanjun2014</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="show_sql">true</property>
<mapping resource="com/pojo/Emp.hbm.xml" />                映射类xml
</session-factory>
</hibernate-configuration>

在里面可以增加连接池


配置类属性

类名.hbm.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="com.pojo.Emp" table="emp">
      <id name="empId" column="empId">
         <generator class="native"></generator>
      </id>     
      <property name="empName" column="empName"></property>
     <property name="did" column="did"></property>      
   </class>
</hibernate-mapping>

多对一 <!-- 关系 -->
      <many-to-one name="dep" column="did">
      </many-to-one>

一对多

<!-- 关系 cascade="delete,save-update,none,all"  -->
      <set name="emps" cascade="delete,save-update">
        <key column="did"></key>
        <one-to-many class="com.pojo.Emp" />
      </set>


配置spring

beans.xml

<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
        xsi:schemaLocation="  
            http://www.springframework.org/schema/beans   
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">    
    <bean name="empDao" class="com.dao.EmpDAO"></bean>
    <bean name="empService" class="com.service.EmpService" scope="prototype">  
    <property name="empDao" ref="empDao"></property>
    </bean>  
    <bean name="empAction" class="com.action.EmpAction">
    <property name="empService" ref="empService"></property>
    </bean>
</beans>  


配置web.xml

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <context-param>  
        <param-name>contextConfigLocation</param-name>  
        <param-value>classpath:beans.xml</param-value>  
    </context-param>  
        
    <listener>  
        <listener-class>  
            org.springframework.web.context.ContextLoaderListener  
        </listener-class>  
    </listener>  
     <filter>  
        <filter-name>Struts2</filter-name>  
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        <!--  <filter-class>com.kairgus.common.FCKFilter</filter-class>-->
    </filter>  
    <filter-mapping>  
        <filter-name>Struts2</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>  
    <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>

注:

在struts-core-2.3.15.1.jar之后<file-class>中可以是 <filter-class>com.kairgus.common.FCKFilter</filter-class>

具体操作是在com.kairgus.common包(可以任意)中增加FCKFilter(名字可以任意)类,具体类的实现如下:

package com.kairgus.common;
import java.io.IOException; 
import javax.servlet.FilterChain; 
import javax.servlet.ServletException; 
import javax.servlet.ServletRequest; 
import javax.servlet.ServletResponse; 
import javax.servlet.http.HttpServletRequest; 
import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter; 
public class FCKFilter extends StrutsPrepareAndExecuteFilter { 
    public void doFilter(ServletRequest req,ServletResponse res, FilterChain chain) throws IOException, ServletException {   
        HttpServletRequest request = (HttpServletRequest) req;  
        String URI = request.getRequestURI(); 
        String[] uriArray = URI.split("/fckeditor/editor/filemanager/connectors/"); 
        int arrayLen = uriArray.length; 
        if (arrayLen >= 2) { 
            chain.doFilter(req, res);  
        }else { 
            super.doFilter(req, res, chain);   
        } 
    }  
}


配置struts

struts.xml
<?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.objectFactory" value="spring" />
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="true" />
     <constant name="struts.i18n.encoding" value="GB18030" />
    <package name="default" namespace="/" extends="struts-default">
        <default-action-ref name="index" />
        <global-results>
            <result name="error">/error.jsp</result>
        </global-results>
        <global-exception-mappings>
            <exception-mapping exception="java.lang.Exception" result="error"/>
        </global-exception-mappings>     
        <action name="emp_*" class="empAction" method="{1}">
            <result name="input">error.jsp</result>
            <result name="success">/insertAdmin/enterprise_info.jsp</result>
        </action>  
    </package>
</struts>












































0 0
原创粉丝点击