关于ssm框架的整合步骤

发布时间:2020-04-03 15:12:46   来源:文档文库   
字号:

关于ssm框架的整合步骤

1.什么是ssm

ssm指的是springmvc+spring+mybatis,而且这个组合框架是基于mvc架构的。Springmvc是做控制层的,spring在此中是用来管理业务逻辑层的,mybatis是用来做dao层的。而架构mvc中的m指的是model,其中包含service,dao以及javabean(pojo),其中v指的是视图,

其中的c指的是controller(handler).

2.导入的jar

3.ssm框架配置步骤

1.从web.xml文件开始

不管你用的什么框架,如果你使用的是Tomcat作为服务器,都需要在web.xml中配置一个入口,开启使用的框架,故此,我们先从web.xml文件中开始配置.

Spring是springmvc和mybatis依附的对象。

在web.xml中配置spring监听器,配置如下:

contextConfigLocation

classpath:application-context.xml

在web.xml中配置springmvc的前端控制器(中央处理器),配置如下:

springmvc

contextConfigLocation

classpath:springmvc.xml

1

springmvc

*.do

在web.xml中配置请求时中文乱码过滤器,配置如下:

encoding

encoding

utf-8

encoding

*.do

2.application-context.xml中的配置

3.config包中的jdbc.xml

dataSourceclass=”>

4.config包中的property.xml

使用下面这种配置,有利于扩展

locations>

classpath:jdbc.properties

5.config包中的jdbc.properties的配置

driverClass=

jdbcUrl=

user=root

password=

6.config包中的annotation.xml的配置

com.donghua>

annotationexpression=””/>

7.config包中的transaction.xml的配置

transactionManager””class=>

dataSourceref=dataSource>

<!--开启注解-->

transactionManager”/>

8.config包中的mybatis.xml的配置

sqlSessionFactoryclass=>

dataSourceref=dataSource/>

configLocationvalue=classpath:mybatis-config.xml/>

basePackagevalue=/>

9.mybatis-config.xml中的配置

lazyLoadingEnabledvalue=true/>

aggressiveLazyLoadingvalue=false/>

cacheEnabledvalue=true/>

””/>

10.springmvc.xml中的配置

com.donghuause-default-filters=false>

annotationexpression=””>

jspViewResolverclass=>

prefixvalue=/WEB-INF/jsp//>

suffixvalue=.jsp/>

conversionServicevalidator=validator/>

validatorclass=>

providerClassvalue=/>

conversionServiceclass=>

converters>

””/>

multipartResolver”class=>

maxUploadSizevalue=1048576/>

11.springmvc.xml中配置全局异常处理

需要自定义一个异常处理类,例如:

然后在springmvc.xml中,配置一个该类的bean

12.springmvc.xml中配置校验

1步:导入必须的jar

2步:在javabean上打注解

3步:生成分组的接口

4步:在springmvc.xml文件中配置

<mvc:annotation-drivenconversion-service="conversionService"validator="validator"/>

<beanid="validator"class=>

<propertyname="providerClass"value=/>

<propertyname="validationMessageSource"ref="messageSource"/>

bean>

<beanid="messageSource"class=>

<propertyname="basenames">

<list>

<value>classpath:messagevalue>

list>

property>

<propertyname="fileEncodings"value="utf-8"/>

<propertyname="cacheSeconds"value="120"/>

bean>

5步:编写message.properties文件

itemsNameSize=\u8BF7\u8F93\u51651-5\u4E4B\u95F4\u7684\u6570

itemsName=\u4E0D\u4E3A\u7A7A

13.springmvc的前端控制器的接收的请求是/时的配置

web.xml中的配置如下,给springmvc前端控制器添加的另外一个映射路径:

<servlet-mapping>

<servlet-name>springmvcservlet-name>

<url-pattern>/url-pattern>

servlet-mapping>

也要也中文乱码过滤器,配置添加一个新的过滤映射路径

<filter-mapping>

<filter-name>encodingfilter-name>

<url-pattern>/url-pattern>

filter-mapping>

我们需要让springmvc的前端控制器不拦截.css.js..doc...

在springmvc.xml中的配置如下:

14.springmvc.xml中配置拦截器

<mvc:interceptors>

<mvc:interceptor>

<mvc:mappingpath="/*/**"/>

<beanclass=>bean>

mvc:interceptor>

mvc:interceptors>

本文来源:https://www.2haoxitong.net/k/doc/03c90436f32d2af90242a8956bec0975f465a421.html

《关于ssm框架的整合步骤.doc》
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档

文档为doc格式