bugstar

导航

30.SSH配置文件模板.md

1.struts2

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
    <display-name>StrutsDemo1</display-name>

    <!-- 引入struts核心过滤器 -->
    <!-- 其实就是配置一个普通的过滤器 -->
    <filter>
        <!-- struts2引入 -->
        <filter-name>stucts2</filter-name>
        <!-- 核心类:StrutsPrepareAndExecuteFilter。可以用ctrl + shift + t中输入 -->
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class>
    </filter>

    <filter-mapping>
        <!-- struts2引入 -->
        <filter-name>stucts2</filter-name>
        <!-- 过滤所有网页 -->
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

2.Hibernate

2.1类配置

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Nov 9, 2006 6:27:53 PM by Hibernate Tools 3.2.0.beta7 -->
<!-- package:类对象所在的包
     auto-import:表面是自动导入包,如果设定为false,则需要在执行hql语句时候将包名写清楚:
     Demo:在true时候可以写为session.createQuery("from Employee").list();
               在false时候必须写为session.createQuery("from per.liyue.code.hibernatehello.Employee").list();
 -->
<hibernate-mapping package="per.liyue.code.hibernatehello" auto-import="true">
    <!-- 类与表的对应
         name:类名称
         table:表名称

     -->
    <class name="Employee" table="employee">
        <!-- 主键 注意和类成员和表列名称的一致对应 -->
        <id name="empId" column="EmpId" >
            <!-- 主键的生成策略:
                 1.identity  自增长(mysql,db2)
                 2.sequence  自增长(序列), oracle中自增长是以序列方法实现
                 3.native  自增长【会根据底层数据库自增长的方式选择identity或sequence】
                            如果是mysql数据库, 采用的自增长方式是identity
                            如果是oracle数据库, 使用sequence序列的方式实现自增长

                 4.increment  自增长(会有并发访问的问题,一般在服务器集群环境使用会存在问题。)

                 5.assigned  指定主键生成策略为手动指定主键的值
                 6.uuid      指定uuid随机生成的唯一的值
                 7.foreign   (外键的方式, one-to-one讲)
             -->
            <generator class="native" />

        </id>
        <!-- 非主键,同样一一映射
             name:类的属性名称
             column:表的字段名称
             length:设定字段的长度,默认为255
             type:设定映射表的类型,如果不写匹配类对应属性的类型
                     java类型:必须带完整包名:java.lang.String
                     hibernate类型:全部都是小写

        -->
        <property name="empName" column="EmpName"></property>
        <property name="workDate" column="WorkDate"></property>
    </class>
</hibernate-mapping>  
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory name="foo">
        <!-- 数据库连接配置 -->
        <!-- 连接类 -->
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <!-- 连接数据库 -->
        <property name="hibernate.connection.url">jdbc:mysql:///hi</property>
        <!-- 连接用户名 -->
        <property name="hibernate.connection.username">root</property>
        <!-- 连接密码 -->
        <property name="hibernate.connection.password">root</property>
        <!-- 数据库方言 -->
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>

        <!-- 加载所有的映射 -->
        <mapping resource="per/liyue/code/hibernatehello/Employee.hbm.xml"/>
    </session-factory>
</hibernate-configuration>  

3.Spring

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
</beans>

posted on 2016-11-10 14:05  bugstar  阅读(113)  评论(0编辑  收藏  举报