源代码下载:SSM实现用户登陆
前面讲过了 spring+mybatis的配置 spring+mybatis
只要再加上spring MVC spring MVC基础 就组合成了SSM框架
1、配置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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
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.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd ">
<!-- 引入数据库配置文件 -->
<context:property-placeholder location="classpath:com/ssmTest/system/config/db.properties"/>
<!-- 数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<!-- 初始连接池大小 -->
<property name="initialPoolSize" value="${jdbc.initialPoolSize}"/>
<!-- 连接池中连接最小个数 -->
<property name="minPoolSize" value="${jdbc.minPoolSize}"/>
<!-- 连接池中连接最大个数 -->
<property name="maxPoolSize" value="${jdbc.maxPoolSize}"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.ssmTest.system.*.*.mapper"></property>
</bean>
<!-- 配置注解扫描 用 @类名 的原因在这配置 -->
<context:component-scan base-package="com.ssmTest.system.*.*.service"></context:component-scan>
<context:component-scan base-package="com.ssmTest.system.*.*.pojo"></context:component-scan>
<!-- 配置事务管理 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 注入数据源 保证了数据库的四大特性-->
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 传播行为 每次调用这些方法都会启动 事务管理 每个在config里配置的方法都要以以下方式开头-->
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="R