SSH框架搭建

1.web.xml
    dispatcherServlet  前端控制器配置在web.xml文件中的。
        拦截匹配的请求,Servlet拦截匹配规则要自己定义,
        把拦截下来的请求,依据相应的规则分发到目标Controller来处理,
        是配置spring MVC的第一步。是前端控制器设计模式的实现,
        提供Spring Web MVC的集中访问点,而且负责职责的分派,
        而且与Spring IoC容器无缝集成,从而可以获得Spring的所有好处。
    ContextLoaderListener  监听器的作用就是启动Web容器时,自动装配ApplicationContext的配置信息
    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    
        <init-param>
            <param-name>encoding</param-name>
            <param-value>utf-8</param-value>
        </init-param>
    </filter>
    
    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>//*</url-pattern>    
    </filter-mapping>
    
2.applicationContext
    <!-- 1.加载数据库配置文件-->
    <context:property-placeholder location="classpath:jdbc.properties"/>
    <!-- 2.数据源 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${jdbc.driverClass}"></property>
        <property name="jdbcUrl" value="${jdbc.url}"></property>
        <property name="user" value="${jdbc.username}"></property>
        <property name="password" value="${jdbc.password}"></property>
    </bean>
    <!-- 3.配置SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
         <property name="hibernateProperties">
             <props>
                 <prop key="hibernate.show_sql">true</prop>
                 <prop key="hibernate.format_sql">true</prop>
                 <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                 <prop key="hibernate.hbm2ddl.auto">update</prop>    
             </props>
         </property>
         <property name="mappingLocations" value="classpath:com/lp/domain/*.hbm.xml"></property>
    </bean>
    <!-- 4.dao -->
    
    <!-- 5.service -->
    
    <!-- 6.平台事务管理器 -->
    <bean id="txManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <!-- 7.通知 -->
    <tx:advice id="txAdvice" transaction-manager="txManager">
        <tx:attributes>
            <tx:method name="*"/>
        </tx:attributes>
    </tx:advice>
    <!-- 8.aop管理实务 -->
    <aop:config>
        <aop:pointcut expression="execution(* com.lp.service..*.*(..))" id="myPointcut"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="myPointcut"/>
    </aop:config>
    <!-- 9.配置springmvc -->
    <context:component-scan base-package="com.lp"></context:component-scan>
    
    <mvc:annotation-driven></mvc:annotation-driven>
    
    <!-- 10.视图解析器 -->
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
    
3.dao service  加注解
    service extends HibernateDaoSupport
        @Resource
        public void setMySessionFactory(SessionFactory sessionFactory) {
            super.setSessionFactory(sessionFactory);

        }
        
4.xml
    <hibernate-mapping auto-import="true" default-access="property" default-cascade="none" default-lazy="true">
    <class catalog="crm" dynamic-insert="false" dynamic-update="false" mutable="true" name="com.lp.domain.Authority" optimistic-lock="version" polymorphism="implicit" select-before-update="false" table="authority">
        <id name="authId" type="string">
            <column name="authId"/>
            <generator class="uuid"/>
        </id>
        <property generated="never" lazy="false" name="url" optimistic-lock="true" type="string" unique="false">
            <column name="url"/>
        </property>
        <property generated="never" lazy="false" name="desc" optimistic-lock="true" type="string" unique="false">
            <column name="desc"/>
        </property>
        <set embed-xml="true" fetch="select" inverse="true" lazy="true" mutable="true" name="roles" optimistic-lock="true" sort="unsorted" table="roleauthority">
            <key on-delete="noaction">
                <column name="authId" not-null="true"/>
            </key>
            <many-to-many embed-xml="true" entity-name="com.lp.domain.Role" not-found="exception" unique="false">
                <column name="roleId" not-null="true"/>
            </many-to-many>
        </set>
    </class>
</hibernate-mapping>
        
       
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值