ssm整合

一、Maven jar包

   

  •     <dependencies>
  •         <!-- servlet包 -->
  •         <dependency>
  •             <groupId>javax.servlet</groupId>
  •             <artifactId>javax.servlet-api</artifactId>
  •             <version>3.1.0</version>
  •             <scope>provided</scope>
  •         </dependency>
  •         <dependency>
  •             <groupId>junit</groupId>
  •             <artifactId>junit</artifactId>
  •             <version>4.11</version>
  •             <scope>test</scope>
  •         </dependency>
  •         <dependency>
  •             <groupId>org.mybatis</groupId>
  •             <artifactId>mybatis-spring</artifactId>
  •             <version>1.3.2</version>
  •         </dependency>
  •         <dependency>
  •             <groupId>org.springframework</groupId>
  •             <artifactId>spring-tx</artifactId>
  •             <version>4.3.20.RELEASE</version>
  •         </dependency>
  •         <dependency>
  •             <groupId>org.springframework</groupId>
  •             <artifactId>spring-jdbc</artifactId>
  •             <version>4.3.20.RELEASE</version>
  •         </dependency>
  •         <dependency>
  •             <groupId>org.springframework</groupId>
  •             <artifactId>spring-expression</artifactId>
  •             <version>4.3.20.RELEASE</version>
  •         </dependency>
  •         <dependency>
  •             <groupId>org.springframework</groupId>
  •             <artifactId>spring-context-support</artifactId>
  •             <version>4.3.20.RELEASE</version>
  •         </dependency>
  •         <dependency>
  •             <groupId>org.springframework</groupId>
  •             <artifactId>spring-context</artifactId>
  •             <version>4.3.20.RELEASE</version>
  •         </dependency>
  •         <dependency>
  •             <groupId>org.springframework</groupId>
  •             <artifactId>spring-web</artifactId>
  •             <version>4.3.20.RELEASE</version>
  •         </dependency>
  •         <!-- springmvc-jar -->
  •         <dependency>
  •             <groupId>org.springframework</groupId>
  •             <artifactId>spring-webmvc</artifactId>
  •             <version>4.3.20.RELEASE</version>
  •         </dependency>
  •         <dependency>
  •             <groupId>commons-logging</groupId>
  •             <artifactId>commons-logging</artifactId>
  •             <version>1.1.1</version>
  •         </dependency>
  •         <dependency>
  •             <groupId>commons-pool</groupId>
  •             <artifactId>commons-pool</artifactId>
  •             <version>1.6</version>
  •         </dependency>
  •         <!-- 数据源 -->
  •         <dependency>
  •             <groupId>commons-dbcp</groupId>
  •             <artifactId>commons-dbcp</artifactId>
  •             <version>1.4</version>
  •         </dependency>
  •         <dependency>
  •             <groupId>log4j</groupId>
  •             <artifactId>log4j</artifactId>
  •             <version>1.2.17</version>
  •         </dependency>
  •         <dependency>
  •             <groupId>org.mybatis</groupId>
  •             <artifactId>mybatis</artifactId>
  •             <version>3.4.6</version>
  •         </dependency>
  •         <dependency>
  •             <groupId>org.testcontainers</groupId>
  •             <artifactId>mysql</artifactId>
  •             <version>1.11.1</version>
  •             <scope>test</scope>
  •         </dependency>
  •         <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
  •         <dependency>
  •             <groupId>mysql</groupId>
  •             <artifactId>mysql-connector-java</artifactId>
  •             <version>5.1.6</version>
  •         </dependency>
  •     </dependencies>

   

   

二、配置文件

   

   

  • <?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: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-4.3.xsd">
  •     <!-- 数据源和mapper -->
  •     <!-- 配置数据库信息 -->
  •     <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  •         <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  •         <property name="url" value="jdbc:mysql://localhost:3306/project"/>
  •         <property name="username" value="root"/>
  •         <property name="password" value="admin"/>
  •     </bean>
  •     
  •     <!-- 配置sqlSessionFactory -->
  •      <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  •              <property name="dataSource" ref="dataSource"/>
  •              <!--加载所有的的mapper映射文件-->
  •              <property name="mapperLocations" value="classpath:cn/tri/mapper/*.xml"></property>
  •     </bean>
  •     
  •     <!-- spring整合mybaties-->
  •     <!-- 自动扫描包,并且生成mapper的实现类,生成的bean的名称为mapper接口的首字母小写 -->
  •     <bean id="mappers" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  •         <!-- 配置映射文件 ,该包下的接口统统转化成类,例如  personMapper(首字母小写)-->
  •         <property name="basePackage" value="cn.tri.mapper"></property>
  •         <!-- 将mybaites的sqlSessionFactory交给spring管理 -->
  •         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
  •     </bean>
  •     
  •      <bean id="personServiceImp" class="cn.tri.serviceImp.PersonServiceImp">
  •      ????????<property name="personMapper" ref="personMapper"></property>
  •      </bean>
  •     <!--  <bean id="servletPerson" class="cn.tri.servlet.ServletPerson">

         ????????<property name="personService" ref="personServiceImp"></property>

        </bean> -->
  • </beans>

   

web.xml配置

   

   

posted @ 2020-10-19 21:29  黑质白章  阅读(75)  评论(0编辑  收藏  举报