关于ssm框架的整合步骤Word下载.docx
《关于ssm框架的整合步骤Word下载.docx》由会员分享,可在线阅读,更多相关《关于ssm框架的整合步骤Word下载.docx(9页珍藏版)》请在冰点文库上搜索。
![关于ssm框架的整合步骤Word下载.docx](https://file1.bingdoc.com/fileroot1/2023-4/30/83dc33e3-e4f0-4945-a1f1-3e48e8b17836/83dc33e3-e4f0-4945-a1f1-3e48e8b178361.gif)
listener>
listener-class>
/listener-class>
/listener>
在中配置springmvc的前端控制器(中央处理器),配置如下:
servlet>
servlet-name>
springmvc<
/servlet-name>
init-param>
contextConfigLocation<
/init-param>
--加载配置文件的时候立即实例化-->
load-on-startup>
1<
/load-on-startup>
/servlet>
servlet-mapping>
--/*:
拦截所有的请求跳转视图都会拦截比如/WEB-INF/jsp/
/:
拦截所有的请求跳转视图不拦截不过会拦截.拦截.do后缀的请求
-->
url-pattern>
*.do<
/url-pattern>
/servlet-mapping>
在中配置请求时中文乱码过滤器,配置如下:
filter>
filter-name>
encoding<
/filter-name>
filter-class>
/filter-class>
encoding<
utf-8<
/filter>
filter-mapping>
/filter-mapping>
2.在中的配置
--所有的配置文件从这里导入-->
importresource=”config/*.xml”/>
3.在config包中的
--配置c3p0连接池-->
beanid=”dataSource”class=””>
propertyname=”driverClass”value=”${driverClass}”/>
propertyname=”jdbcUrl”value=”${jdbcUrl}”/>
propertyname=”user”value=”${user}”/>
propertyname=”password”value=”${password}”/>
/bean>
4.在config包中的
--读取文件-->
--这种写法不利于扩展-->
context:
property-placeholderlocation=”classpath:
”/>
使用下面这种配置,有利于扩展
beanclass=>
propertyname=”locations”>
list>
value>
/value>
/list>
/property>
5.在config包中的的配置
driverClass=
jdbcUrl=
user=root
password=
6.在config包中的的配置
--扫描包-->
component-scanbase-package=””>
exclude-filtertype=”annotation”expression=””/>
/context:
component-scan>
7.在config包中的的配置
--配置数据源事务注解式开发-->
beanid=”transactionManager””class=>
propertyname=d”ataSource”ref=da”taSource”>
--开启注解-->
/>
tx:
annotation-driventransaction-manager=”transactionManager
8.在config包中的的配置
--sqlSessionFactory工厂-->
beanid=”sqlSessionFactory”class=>
--注入数据源-->
propertyname=”dataSource”ref=”dataSource”/>
--配置核心配置文件所在位置-->
propertyname=”configLocation”value=”classpath:
--Mapper接口动态代理开发升级扫描-->
propertyname=”basePackage”value=/>
<
9.在中的配置
settings>
!
--开启懒加载-->
settingname=”lazyLoadingEnabled”value=”true”/>
--加载必须的-->
settingname=”aggressiveLazyLoading”value=”false”/>
--开启二级缓存-->
settingname=”cacheEnabled”value=”true”/>
/settings>
--为类类型启别名为的是简化书写<
typeAliases>
packagename=””/>
/typeAliases>
10.在中的配置
--扫描-->
component-scanbase-package=””-udseefault-filters=”false”>
include-filtertype=”annotation”expression=””>
--视图解释器-->
beanid=”jspViewResolver”class=>
propertyname=”prefix”value=-I”NF/W/jsEpB/”/>
propertyname=”suffix”value=”.jsp”/>
--注解式处理器映射器和处理器适配器-->
validator
mvc:
annotation-drivenconversion-service=”conversionService”validator=/>
--校检-->
beanid=”validator”class=>
propertyname=”providerClass”value=/>
--日期转换器-->
beanid=”conversionService”class=>
propertyname=”converters”>
beanclass=””/>
v/property>
v/bean>
beanid=”multipartResolver”class=>
--设置文件上传大小默认单位B要求1M-->
vpropertyname=”maxUploadSize”value=”1048576”/>
/bean>
11.在中配置全局异常处理
需要自定义一个异常处理类,例如:
然后在中,配置一个该类的bean
12.在中配置校验
第1步:
导入必须的jar包
第2步:
在javabean上打注解
第3步:
生成分组的接口
第4步:
在文件中配置
--注解式-->
annotation-driven
conversion-service="
conversio
nService"
validator="
validator"
/>
--校验-->
beanid="
class=>
propertyname="
providerClass"
value=/>
--指定信息保存位置-->
propertyname="
validationMessageSource"
ref="
messageSource"
/bean>
--读取文件的类-->
beanid="
messageSource"
--资源文件名-->
basenames"
>
list>
value>
message<
/value>
/list>
/property>
--资源文件编码格式-->
fileEncodings"
value="
utf-8"
--对资源文件缓存时间,单位秒-->
cacheSeconds"
120"
第5步:
编写文件
itemsNameSize二\u8BF7\u8F93\u51651-5\u4E4B\u95F4\u7684
\u6570
itemsName=\u4E0D\u4E3A\u7A7A
13.当springmvc的前端控制器的接收的请求是/时的配置
在中的配置如下,给springmvc前端控制器添加的另外一个映射路径:
vservlet-mapping
>
vservlet-name
springmvc<
/servlet-name>
vurl-pattern
/<
/url-pattern>
/servlet-mapping>
也要也中文乱码过滤器,配置添加一个新的过滤映射路径
vfilter-mapping
vfilter-name
/filter-name>
/filter-mapping
我们需要让springmvc的前端控制器不拦截…doc...
在中的配置如下
14.在中配置拦截器
--springmvc拦截器-->
interceptors>
interceptor>
--设置拦截规则-->
mappingpath="
/*/**"
--拦截器类-->
beanclass=>
/bean>
v/mvc:
/mvc:
interceptors>