1、listenerlistener-class/listener-class/listener在中配置 springmvc 的前端控制器 ( 中央处理器 ), 配置如下:servletservlet-namespringmvcinit-paramcontextConfigLocation - 加载配置文件的时候立即实例化 -load-on-startup1/servletservlet-mapping-/*: 拦截所有的请求跳转视图都会拦截比如 /WEB-INF/jsp/: 拦截所有的请求跳转视图不拦截不过会拦截 . 拦截 .do 后缀的请求-url-pattern*.do/servlet-ma
2、pping在中配置请求时中文乱码过滤器 , 配置如下:filterfilter-nameencodingfilter-class/filter-classencoding utf-8filter-mapping/filter-mapping2.在中的配置- 所有的配置文件从这里导入 -importresource= ”config/*.xml ” /3. 在 config 包中的- 配置 c3p0 连接池 -beanid= ”dataSource ” class= ”propertyname= ”driverClass ” value= ”$driverClass ”/propertyname
3、= ”jdbcUrl ”value= ”$jdbcUrl ”/propertyname=”user”value= ”$user ”/propertyname= ”password” value= ”$password ”/bean4. 在 config 包中的- 读取文件 - 这种写法不利于扩展 -context:property-placeholderlocation= ” classpath: ”/使用下面这种配置,有利于扩展beanclass=propertyname= ”locations ”listvalue/value/list/property5. 在 config 包中的的配置
4、driverClass=jdbcUrl=user=rootpassword=6. 在 config 包中的的配置-扫描包-component-scanbase-package= ”exclude-filtertype= ” annotation ” expression= ” /context:component -scan7. 在 config 包中的的配置-配置数据源事务注解式开发 -beanid= ” transactionManager ” class=propertyname= d”ataSource ” ref=da”taSource ” -开启注解 -/tx:annotation
5、 -driventransaction-manager=” transactionManager8. 在 config 包中的的配置-sqlSessi onF actory工厂-beanid= ”sqlSessionFactory ”class=-注入数据源 -propertyname= ” dataSource ”ref= ”dataSource ”/-配置核心配置文件所在位置 -propertyname= ”configLocation ”value= ”classpath:-Mapper 接口动态代理开发升级扫描 -propertyname= ”basePackage”value=/ !
6、 -开启懒加载 -settingname= ”lazyLoadingEnabled ”value= ”true ”/ -加载必须的 -settingname= ”aggressiveLazyLoading ”value= ”false ”/ -开启二级缓存 -settingname= ”cacheEnabled ”value= ”true ”/settings-为类类型启别名为的是简化书写 packagename=” /typeAliases10. 在中的配置-扫描-component-scanbase-package= ”-udseefault -filters= ” false ”incl
7、ude-filtertype= ” annotation ” expression= ”-视图解释器 -beanid= ” jspViewResolver ” class=propertyname= ” prefix ” value=-I”NF/W/jsEpB/ ”/propertyname= ” suffix ” value= ” .jsp ” /-注解式处理器映射器和处理器适配器 -validatormvc:annotation-drivenconversion-service= ” conversionService ” validator= /-校检-beanid= ” validat
8、or ” class=propertyname= ” providerClass ” value=/-日期转换器 -beanid= ” conversionService ” class=propertyname= ” converters ”beanclass= ” /v/propertyv/bea nbeanid= ” multipartResolver ” class=-设置文件上传大小默认单位 B要求1M-vpropertyname= ” maxUploadSize ” value= ” 1048576” /bea n11. 在中配置全局异常处理需要自定义一个异常处理类,例如:然后在中
9、,配置一个该类的bean12. 在中配置校验第1步:导入必须的jar包第2步:在javabean上打注解第3步:生成分组的接口第4步:在文件中配置-注解式-a nn otatio n-drive nconv ersi on-service =c onv ersionService validator = validator /-校验-bea nid = class =property n ame=providerClass value =/- 指定信息保存位置 -property name=validationMessageSource ref =message Source/ bean -
10、读取文件的类 -bean id =messageSource- 资源文件名 -basenames list value message / list / property - 资源文件编码格式 -fileEncodings value =utf-8- 对资源文件缓存时间 , 单位秒 -cacheSeconds120第5步:编写文件itemsNameSize二 u8BF7u8F93u51651-5u4E4Bu95F4u7684u6570itemsName= u4E0Du4E3Au7A7A13. 当springmvc的前端控制器的接收的请求是 /时的配置在中的配置如下,给 springmvc前端控
11、制器添加的另外一个映射路径:vservlet-mapp ingvservlet- namespringmvc vurl-patter n/ / servlet-mapping 也要也中文乱码过滤器,配置添加一个新的过滤映射路径vfilter-mapp ingvfilter- name/ filter-name / filter-mapping我们需要让springmvc的前端控制器不拦截doc.在中的配置如下14. 在中配置拦截器-spri ngmvc 拦截器-i nterceptors i nterceptor -设置拦截规则-mapping path =/*/*-拦截器类-bean class =/ beanv/mvc:/ mvc:interceptors
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2