• ssm整合


    导入jar

    编写核心配置文件

    web.xml       ---sprinp配置和springmvc配置

      <!-- spring配置文件  ================================================================================== -->
      <context-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>classpath:applicationContext.xml</param-value>
      </context-param>
      
      <listener>
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
      
      <!-- srping mvc配置文件 ============================================================================== -->
      <servlet>
          <servlet-name>springmvc</servlet-name>
          <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
                <init-param>
              <param-name>contextConfigLocation</param-name>
              <param-value>classpath:mvc.xml</param-value>
          </init-param>
          
          <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
          <servlet-name>springmvc</servlet-name>
          <url-pattern>*.do</url-pattern>
      </servlet-mapping>

    mvc.xml  ---spring

        <!-- spring扫描的包 -->
        <context:component-scan base-package="cn.zys.controller"></context:component-scan>

    applicationContext ---spring

        <?xml version="1.0" encoding="UTF-8<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc
    ="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/tx https://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- 外部引入数据库配置 --> <bean class="org.springframework.beans.factory.config.PlaceholderConfigurerSupport"> <property name="location" value="classpath:db.properties"></property> </bean> <context:property-placeholder location="db.properties"/> <!-- 配置 datasource --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driver" value="${driver}"/> <property name="url" value="${url}"/> <property name="username" value="${username}"/> <property name="password" value="${password}"/> </bean> <!-- 配置工厂 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 配置声明事务 --> <!-- 事务管理器 --> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property>
         <property name="configLocation" value="classpath:mybatis.config.xml"></property>
    </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*" propagation="REQUIRED"/> <tx:method name="get" read-only="true"/> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut expression="execution(* cn.zys.service.*.*(..))" id="pointcut"/> <!-- 在所有的方法中都切入前置通知--> <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut"/> </aop:config> <!-- 注解 --> <context:component-scan base-package="cn.zys"></context:component-scan> <!-- <mvc:annotation-driven/> --> </beans>

    mybatis.cfg.xml ---mybatis

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE configuration
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-config.dtd">
    <configuration>
        <typeAliases>
            <package name="cn.zys.vo"/>
        </typeAliases>
        <mappers>
            <!-- 所有mapper文件填写位置 -->
        </mappers>
    </configuration>
  • 相关阅读:
    .net2.0 母板页面和自定义控件有冲突我的错
    ASP.NET程序中常用的三十三种代码
    sql server日期时间函数
    控制面板里的CPL
    [原创]ASP.NET MVC多域名多站点解析问题
    SQL获取字段html代码中的img标签图片文件的路径
    [原创]ASP.NET MVC控制器中动态解析用户控件
    EasyUI的treegrid组件动态加载数据问题解决办法
    ASP.NET MVC使用EasyUI的datagrid多选提交保存教程
    [原创]IE6下wbox弹出iframe窗口加载页面空白问题解决
  • 原文地址:https://www.cnblogs.com/xiaozhang666/p/11670380.html
Copyright © 2020-2023  润新知