ssm框架
spring IOC DI AOP
spring-beans
spring-context
spring-core
spring-expression
spring-context-support
如果想用aop切面
aop切面有关的jar包
spring-aop
spring-sapect
aspectjweaver
aopaliance
spring事务管理
spring-tx
spring-web
spring-webmvc
commons-logging ------spring框架依赖的
servlet ------ 底层servlet
fastjson --------- JSON转换工具类
fileupload
commons-io ------- 文件上传
spring和springmvc属于同一个公司,maven又会自动导入依赖的jar包。
spring+springmvc在maven中需要引入
其所依赖的jar包都标相同颜色了
spring-webmvc
javax.servlet-api
commons-logging
spring-context-support
用到aop切面才引入的jar
spring-sapect
aopaliance
用到事务才引入的jar
spring-tx
用到json数据转化才用到的jar
fastjson
用到文件上传才用到的jar
fileupload
连接数据库,jdbc基础上完成复杂的操作
mysql连接数据库用到的jar
mysql-connector-java
dbcp c3p0 druid 不同的连接池用不同的jar
mybaits
pagehelper ------ 分页插件
log4j ------- 日志输出
在maven中需要引入的jar
mybaits
mysql-connector-java
c3p0
pagehelper
log4j
spring+springmvc 同一个公司不需要引入
spring+jdbc
spring-jdbc ----------- 两个结合使用
spring+mybaits
spring-orm
mybaits-spring
在maven中需要引入的jar
spring-jdbc
spring-orm
mybaits-spring
我所用到的jar包有以上这些
tomcat启动时自动加载web.xml配置文件,tomcat启动时,如果需要自动加载spring,springmvc的配置文件,就需要在web.xml配置
spring:创建bean工厂 bean对象
springmvc:监听请求,处理请求,响应数据
<context-param>
<param-name>contextConfigLocationparam-name>
<param-value>classpath:applicationContext.xmlparam-value>
context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class>
listener>
<servlet>
<servlet-name>mvcservlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
<init-param>
<param-name>contextConfigLocationparam-name>
<param-value>classpath:springmvc-servlet.xmlparam-value>
init-param>
servlet>
<servlet-mapping>
<servlet-name>mvcservlet-name>
<url-pattern>/url-pattern>
servlet-mapping>
上面的只要是ssm都是必须要配置的
post请求中文乱码问题解决方案
<filter>
<filter-name>encodingfilter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
<init-param>
<param-name>encodingparam-name>
<param-value>utf-8param-value>
init-param>
<init-param>
<param-name>forceEncodingparam-name>
<param-value>trueparam-value>
init-param>
filter>
<filter-mapping>
<filter-name>encodingfilter-name>
<url-pattern>/*url-pattern>
filter-mapping>
配置头
<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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
必须的
<context:component-scan base-package="com.lanou.controller">context:component-scan>
内部视图资源解析器 转发有效
可要可不要
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/jsp/">property>
<property name="suffix" value=".jsp">property>
bean>
解决返回json数据乱码问题
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8value>
<value>application/json;charset=UTF-8value>
<value>text/plain;charset=UTF-8value>
<value>application/xml;charset=UTF-8value>
list>
property>
bean>
mvc:message-converters>
mvc:annotation-driven>
springmvc处理不了静态资源的时候配置(我觉得也是可有可无,看你项目中是否有静态资源啦!但一般项目都会有静态资源)
<mvc:resources mapping="/static/**" location="/static/" >mvc:resources>
处理文件上传
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
p:defaultEncoding="UTF-8"
p:maxUploadSize="5242880"
p:uploadTempDir="file:/d:/temp"
/>
定义拦截器
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/user/**"/>
<bean class="com.lanou.interceptor.MyInterceptor">bean>
mvc:interceptor>
mvc:interceptors>
<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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
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/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
开启注解模式 可以省略不写,默认开启状态
<context:annotation-config>context:annotation-config>
<context:component-scan base-package="com.lanou.util,com.lanou.service,com.lanou.mapper">context:component-scan>
开启aop注解功能
<aop:aspectj-autoproxy>aop:aspectj-autoproxy>
加载db.properties配置文件
<context:property-placeholder location="classpath:db.properties">context:property-placeholder>
<bean name="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
p:jdbcUrl="${jdbc.jdbcUrl}"
p:driverClass="${jdbc.driverClass}"
p:user="${jdbc.user}"
p:password="${jdbc.password}">
bean>
bean jdbcTemplate spring框架结合jdbc时用的工具类
<bean name="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
bean>
平台事务管理器
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource">property>
<property name="configLocation" value="classpath:mybatis-config.xml" />
bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.lanou.mapper" />
bean>
通知
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="transfer" propagation="REQUIRED" />
<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
<tx:method name="select*" propagation="SUPPORTS" read-only="true" />
<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
tx:attributes>
tx:advice>
启用事务注解模式
<tx:annotation-driven>tx:annotation-driven>
配置事务织入过程
<aop:config>
<aop:pointcut id="txPointCut" expression="execution(* com..service..*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"/>
aop:config>
定义切面bean
<bean id="logAdvice" class="com.lanou.util.LogAdvice">bean>
<aop:config>
<aop:pointcut id="pc"
expression="execution(* com.lanou.service.*.*(..))"/>
<aop:aspect ref="logAdvice">
<aop:around method="round" pointcut-ref="pc">aop:around>
<aop:before method="before" pointcut-ref="pc">aop:before>
<aop:after method="after" pointcut-ref="pc">aop:after>
<aop:after-returning method="afterReturning" pointcut-ref="pc">aop:after-returning>
<aop:after-throwing method="afterException" pointcut-ref="pc">aop:after-throwing>
aop:aspect>
aop:config>
文件头
mybaits核心配置
<configuration>configuration>
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
<setting name="cacheEnabled" value="true">setting>
<setting name="lazyLoadingEnabled" value="true">setting>
<setting name="aggressiveLazyLoading" value="false">setting>
<setting name="useGeneratedKeys" value="true">setting>
<setting name="logImpl" value="LOG4J">setting>
settings>
<typeAliases>
<package name="com.lanou.pojo">package>
typeAliases>
引入 pageHelper插件
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
plugin>
plugins>
<mappers>
<mapper resource="com/lanou/mapper/ArAccountMapper.xml"/>
<mapper resource="com/lanou/mapper/ArOrderMapper.xml"/>
mappers>
文件头
命名空间
<mapper namespace="com.lanou.mapper.OrdersMapper">mapper>
jdbc.jdbcUrl=jdbc:mysql://localhost:3306/mybaits
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.user=root
jdbc.password=123456
# Global logging configuration
log4j.rootLogger=TRACE, stdout
# MyBatis logging configuration...
log4j.logger.com.lanou.mapper=TRACE
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n