1.jar包
spring的jar包:
spring-aop-4.2.5.RELEASE.jar
spring-aspects-4.2.5.RELEASE.jar
spring-beans-4.2.5.RELEASE.jar
spring-context-4.2.5.RELEASE.jar
spring-core-4.2.5.RELEASE.jar
spring-expression-4.2.5.RELEASE.jar
spring-jdbc-4.2.5.RELEASE.jar
spring-tx-4.2.5.RELEASE.jar
spring-web-4.2.5.RELEASE.jar
spring-webmvc-4.2.5.RELEASE.jar
mybatis的jar包:
asm-4.2.jar
cglib-3.1.jar
commons-logging-1.2.jar
log4j-1.2.17.jar
log4j-api-2.2.jar
log4j-core-2.2.jar
mybatis-3.3.0.jar
mybatis-spring-1.3.0.jar
slf4j-api-1.7.12.jar
slf4j-log4j12-1.7.12.jar
jdbc的jar包:
mysql-connector-java-5.1.20-bin.jar
c3p0的jar包:
c3p0-0.9.5.2.jar
mchange-commons-java-0.2.11.jar
jstl的jar包:
taglibs-standard-compat-1.2.5.jar
taglibs-standard-impl-1.2.5.jar
taglibs-standard-jstlel-1.2.5.jar
taglibs-standard-spec-1.2.5.jar
分页的jar包:
jsqlparser-0.9.5.jar
mybatis-paginator-1.2.15.jar
pagehelper-4.1.6.jar
jackson的jar包:
jackson-annotations-2.6.3.jar
jackson-core-2.6.3.jar
jackson-databind-2.6.3.jar
2.配置web.xml
<!-- 监听器启动spring框架 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext/applicationContext-*.xml</param-value>
</context-param>
<!-- 字符过滤器 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<!-- 对springmvc处理的请求进行转码 -->
<servlet-name>springmvc</servlet-name>
</filter-mapping>
<!-- springmvc配置 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext/springmvc.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>
3.配置jdbc.properties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/rbac?useUnicode=true&characterEncoding=utf8
jdbc.user=root
jdbc.password=123456
c3p0.initialPoolSize=10
c3p0.maxPoolSize=100
c3p0.minPoolSize=10
4.配置application-*.xml
配置application-dao.xml(数据库连接、mybatis配置部署)
<!-- 设置spring扫描器扫描 -->
<context:component-scan base-package="com.bjsxt.rbac">
<!-- 禁止扫描Controller注解的类 -->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="driverClass" value="${jdbc.driver}"/>
<property name="user" value="${jdbc.user}"/>
<property name="password" value="${jdbc.password}"/>
<property name="initialPoolSize" value="${c3p0.initialPoolSize}"/>
<property name="maxPoolSize" value="${c3p0.maxPoolSize}"/>
<property name="minPoolSize" value="${c3p0.minPoolSize}"/>
</bean>
<!-- sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybatis.cfg.xml"/>
</bean>
<!-- mybatis的包扫描器 -->
<bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.bjsxt.rbac.mapper"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
application-*.xml(spring事务管理)
<!-- 设置spring事务管理哪个数据源 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 通知 -->
<!-- 在什么地方,做什么(事务管理) 什么时候 -->
<tx:advice id="myAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 当调用方法是以save开头的方法的时候,要求有一个事务,如果当前没有已经存在的事务,则开启一个事务 -->
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<!-- 以get开头的方法,如果在调用的时候,当前方法已经在事务中运行,则直接运行,如果没有在事务中运行,则也可以运行 -->
<tx:method name="get*" propagation="SUPPORTS"/>
<tx:method name="select*" propagation="SUPPORTS"/>
</tx:attributes>
</tx:advice>
<!-- 切面 -->
<!-- 在什么时候,什么地方,做什么 -->
<!-- 什么时候?事务管理,肯定是在方法开始之前开启一个事务,方法调用完成之后提交事务或者回滚事务 -->
<aop:config>
<!-- 切点:指定什么地方 -->
<aop:pointcut expression="execution(* com.bjsxt.rbac.service.*.*(..))" id="myPcut"/>
<!-- 通知:指定做什么 -->
<aop:advisor advice-ref="myAdvice" pointcut-ref="myPcut"/>
</aop:config>
5.配置mybatis.cfg.xml
<!-- 指定包下的实体类起别名 -->
<configuration>
<typeAliases>
<package name="com.bjsxt.rbac.vo"/>
</typeAliases>
</configuration>
6.配置springmvc.xml
<!-- 设置扫描器扫描controller注解类 -->
<context:component-scan base-package="com.bjsxt.rbac.controller"></context:component-scan>
<!-- HandlerMapping、MappingAdaptor、messageConverter可省略 -->
<!-- 向spring上下文中添加消息转换器,还加入了映射器和适配器 -->
<mvc:annotation-driven />
<!-- 定义拦截器链 -->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<bean class="com.bjsxt.rbac.interceptor.LoginInterceptor"></bean>
</mvc:interceptor>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<bean class="com.bjsxt.rbac.interceptor.UrlInterceptor"></bean>
</mvc:interceptor>
</mvc:interceptors>
<!-- 视图解析器 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/"/>
<property name="suffix" value=".jsp"/>
</bean>
7.源码包三层模式开发。。。
spring的jar包:
spring-aop-4.2.5.RELEASE.jar
spring-aspects-4.2.5.RELEASE.jar
spring-beans-4.2.5.RELEASE.jar
spring-context-4.2.5.RELEASE.jar
spring-core-4.2.5.RELEASE.jar
spring-expression-4.2.5.RELEASE.jar
spring-jdbc-4.2.5.RELEASE.jar
spring-tx-4.2.5.RELEASE.jar
spring-web-4.2.5.RELEASE.jar
spring-webmvc-4.2.5.RELEASE.jar
mybatis的jar包:
asm-4.2.jar
cglib-3.1.jar
commons-logging-1.2.jar
log4j-1.2.17.jar
log4j-api-2.2.jar
log4j-core-2.2.jar
mybatis-3.3.0.jar
mybatis-spring-1.3.0.jar
slf4j-api-1.7.12.jar
slf4j-log4j12-1.7.12.jar
jdbc的jar包:
mysql-connector-java-5.1.20-bin.jar
c3p0的jar包:
c3p0-0.9.5.2.jar
mchange-commons-java-0.2.11.jar
jstl的jar包:
taglibs-standard-compat-1.2.5.jar
taglibs-standard-impl-1.2.5.jar
taglibs-standard-jstlel-1.2.5.jar
taglibs-standard-spec-1.2.5.jar
分页的jar包:
jsqlparser-0.9.5.jar
mybatis-paginator-1.2.15.jar
pagehelper-4.1.6.jar
jackson的jar包:
jackson-annotations-2.6.3.jar
jackson-core-2.6.3.jar
jackson-databind-2.6.3.jar
2.配置web.xml
<!-- 监听器启动spring框架 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext/applicationContext-*.xml</param-value>
</context-param>
<!-- 字符过滤器 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<!-- 对springmvc处理的请求进行转码 -->
<servlet-name>springmvc</servlet-name>
</filter-mapping>
<!-- springmvc配置 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext/springmvc.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>
3.配置jdbc.properties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/rbac?useUnicode=true&characterEncoding=utf8
jdbc.user=root
jdbc.password=123456
c3p0.initialPoolSize=10
c3p0.maxPoolSize=100
c3p0.minPoolSize=10
4.配置application-*.xml
配置application-dao.xml(数据库连接、mybatis配置部署)
<!-- 设置spring扫描器扫描 -->
<context:component-scan base-package="com.bjsxt.rbac">
<!-- 禁止扫描Controller注解的类 -->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="driverClass" value="${jdbc.driver}"/>
<property name="user" value="${jdbc.user}"/>
<property name="password" value="${jdbc.password}"/>
<property name="initialPoolSize" value="${c3p0.initialPoolSize}"/>
<property name="maxPoolSize" value="${c3p0.maxPoolSize}"/>
<property name="minPoolSize" value="${c3p0.minPoolSize}"/>
</bean>
<!-- sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybatis.cfg.xml"/>
</bean>
<!-- mybatis的包扫描器 -->
<bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.bjsxt.rbac.mapper"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
application-*.xml(spring事务管理)
<!-- 设置spring事务管理哪个数据源 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 通知 -->
<!-- 在什么地方,做什么(事务管理) 什么时候 -->
<tx:advice id="myAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 当调用方法是以save开头的方法的时候,要求有一个事务,如果当前没有已经存在的事务,则开启一个事务 -->
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<!-- 以get开头的方法,如果在调用的时候,当前方法已经在事务中运行,则直接运行,如果没有在事务中运行,则也可以运行 -->
<tx:method name="get*" propagation="SUPPORTS"/>
<tx:method name="select*" propagation="SUPPORTS"/>
</tx:attributes>
</tx:advice>
<!-- 切面 -->
<!-- 在什么时候,什么地方,做什么 -->
<!-- 什么时候?事务管理,肯定是在方法开始之前开启一个事务,方法调用完成之后提交事务或者回滚事务 -->
<aop:config>
<!-- 切点:指定什么地方 -->
<aop:pointcut expression="execution(* com.bjsxt.rbac.service.*.*(..))" id="myPcut"/>
<!-- 通知:指定做什么 -->
<aop:advisor advice-ref="myAdvice" pointcut-ref="myPcut"/>
</aop:config>
5.配置mybatis.cfg.xml
<!-- 指定包下的实体类起别名 -->
<configuration>
<typeAliases>
<package name="com.bjsxt.rbac.vo"/>
</typeAliases>
</configuration>
6.配置springmvc.xml
<!-- 设置扫描器扫描controller注解类 -->
<context:component-scan base-package="com.bjsxt.rbac.controller"></context:component-scan>
<!-- HandlerMapping、MappingAdaptor、messageConverter可省略 -->
<!-- 向spring上下文中添加消息转换器,还加入了映射器和适配器 -->
<mvc:annotation-driven />
<!-- 定义拦截器链 -->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<bean class="com.bjsxt.rbac.interceptor.LoginInterceptor"></bean>
</mvc:interceptor>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<bean class="com.bjsxt.rbac.interceptor.UrlInterceptor"></bean>
</mvc:interceptor>
</mvc:interceptors>
<!-- 视图解析器 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/"/>
<property name="suffix" value=".jsp"/>
</bean>
7.源码包三层模式开发。。。