SSM组成:
1.SSM:Spring+SpringMVC+Mybatis
- Spring:基于IOC和AOP的容器框架,用来整合其他框架
- SpringMVC:表现层【controller + 页面】的框架
- Mybatis:基于ORM的数据库持久化框架
集成步骤:
1.集成前准备;
1.1.创建动态web工程
1.2.修改Tomcat配置文件中工程文件根目录
1.3.创建index.jsp进行测试
1.4.导包
2.Spring
3.1.创建资源文件目录resources,并在目录中创建配置文件applicationContext.xml
3.2.在配置中,将当前时间交给Spring管理
3.3.测试当前系统时间
@ContextConfiguration("classpath:applicationContext.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class SpringTest {
@Autowired
private Date now;
@Test
public void testName() throws Exception {
System.out.println(now);
}
}
3.Spring+Mybatis
3.1.创建新的数据库ssm并在其中导入所需的表
3.2.在资源文件夹resources中编写属性文件jdbc.properties
jdbc.dirver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssm
jdbc.username=root
jdbc.password=963963
3.3.将属性文件交给Spring管理
<!-- 加载属性配置文件 -->
<context:property-placeholder location="classpath:jdbc.properties" />
3.4.将连接池对象交给Spring管理
<!-- 将连接池对象交给Spring去管理 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.dirver}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
3.5.测试
@ContextConfiguration("classpath:applicationContext.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class SpringTest {
@Autowired
private DataSource dataSource;
@Test
public void testName2() throws Exception