什么是SSM
SSM(Spring+SpringMVC+MyBatis)框架集由Spring、MyBatis两个开源框架整合而成(SpringMVC是Spring中的部分内容)。常作为数据源较简单的web项目的框架。(摘自百度百科)
百度百科——SSM
applicationContext.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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<!-- 加载数据库连接的配置文件 -->
<context:property-placeholder location="classpath:com/ddw/config/jdbc.properties"/>
<!-- 创建数据源,使用的是dbcp -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${driver}"></property>
<property name="url" value="${url}"></property>
<property name="username" value="${name}"></property>
<property name="password" value="${password}"></property>
</bean>
<!-- 创建sqlSession工厂 -->
<!-- id="sqlSessionFactory" -->
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 注入数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 加载映射文件 -->
<property name="mapperLocations">
<list>
<value>classpath:com/ddw/dao/*Mapper.xml</value>
</list>
</property>
<!-- entity包下所有类,起别名
com.rj182.entity.User ==> User -->
<property name="typeAliasesPackage" value="com.ddw.entity"></property>
</bean>
<!-- 使用IOC实现Dao层的动态代理 -->
<!-- sqlSession.getMapper(UserDao.class)
名字:UserDao ==> userDao -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 在这个包下所有接口由spring动态生成代理对象 -->
<property name="basePackage" value="com.ddw.dao"></property>
</bean>
<!-- 开启注解扫描 -->
<context:component-scan base-package="com.ddw.service"></context:component-scan>
</beans>
jdbc.properties文件
driver=oracle.jdbc.OracleDriver
url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
name