文件资源访问

1、统一资源访问接口

Resource

2、实现类

FileSystemResource 通过文件系统路径访问

ClassPathResource 通过classpath路径访问

ServletContextResource 相对于web根目录路径访问

3、工具类

ResourceUtils 通过classpath:和file:资源前缀路径访问

文件资源操作

1、FileCopyUtils

取代底层的文件操作

2、PropertiesLoaderUtils

操作properties文件(文件要存放在classpath下,否则需要传入resource对象)

3、EncodedResource

对Resource进行编码处理

Web工具类

1、WebApplicationContextUtils

获取WebApplicatoinContext对象

2、WebUtils

封装了原始的Servlet API方法

过滤器和监听器

1、延迟加载过滤器

 <filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>

2、中文乱码过滤器

<filter>
<filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
 

3、Web 应用根目录监听器

可通过System.getProperty("mu.root")或在properties中${mu.root}获取web应用程序根目录

 <context-param>
<param-name>webAppRootKey</param-name>
<param-value>mu.root</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.WebAppRootListener
</listener-class>
</listener>
 

4、Log4J 监听器

该监听器包含了WebAppRootListener的功能,所以配置了这个WebAppRootListener就不用配置了

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<listener>
    <listener-class>
    org.springframework.web.util.Log4jConfigListener
    </listener-class>
</listener>

注意:WebAppRootListener 和 Log4jConfigListener 都只能在Web应用部署后WAR 文件会解包的Web应用服务器上使用。

5、Introspector 缓存清除监听器

保证在 Web 应用关闭的时候释放与其相关的 ClassLoader 的缓存和类引用

<listener>
<listener-class>
org.springframework.web.util.IntrospectorCleanupListener
</listener-class>
</listener>

HtmlUtils

对html字符串进行编码和解码处理

htmlEscape(String input)

htmlUnescape(String input)

Assert

对变更进行条件判断,如果不符合将抛出异常

例如:

Assert.hasText(str,”不能为空字符串”)

str不为null 且必须至少包含一个非空格的字符,否则抛出异常 java.lang.IllegalArgumentException: 不能为空字符串

Spring工具类的更多相关文章

  1. spring 工具类大集合

    接以前的文章 apache-commons 常用工具类 和文章 apache-commons 工具类扩展 小家 Spring 对 spring 的工具类做了详细的介绍(一) 这里我抽出一些好用的类,不 ...

  2. Spring工具类 非spring管理环境中获取bean及环境配置

    SpringUtils.java import org.springframework.beans.BeansException; import org.springframework.beans.f ...

  3. Spring工具类:WebApplicationContextUtils

    当 Web 应用集成 Spring 容器后,代表 Spring 容器的WebApplicationContext对象将以 WebApplicationContext.ROOT_WEB_APPLICAT ...

  4. JDBC JdbTemplate&NamedParameterJdbcTemplate(Spring工具类)

    使用该工具类需要从spring开发包中导入spring.jar和commons-logging.jar,这个模板是线程安全的.   JdbcTemplate: public class JdbcTem ...

  5. spring工具类获取bean

    import org.springframework.web.context.ContextLoader; import org.springframework.web.context.WebAppl ...

  6. 借助Spring工具类如何实现支持数据嵌套的赋值操作

    假设有两个Bean A和B,想将B中的属性赋值到A实体中,可以使用get set来实现,当属性过多时,就会显得很冗余,可以使用spring提供的BeanUtils.copyProperties()来实 ...

  7. 你可能用到的Spring工具类?

    现在绝大部分项目都已经拥抱Spring生态,掌握Spring常用的工具类,是非常重要,零成本增加编码效率. 一.常用工具类 ObjectUtils org.springframework.util.O ...

  8. Spring工具类ToStringBuilder用法简介

    比如说我们需要打印某个方法的User参数对象 package test; /** * * @author zhengtian * @time 2012-6-28 */ public class Use ...

  9. 通过spring工具类获取bean

    package xxx; import org.springframework.beans.BeansException; import org.springframework.beans.facto ...

随机推荐

  1. Android app启动耗时分析

    前言 app启动耗时过长的话,无论你的app里面的内容多么丰富有趣,作为一个用户,首先是没有耐心去等待的,如果我是一个用户,我会这样想:这是什么垃圾公司出的什么烂app,再等2s不进来就卸载,黑人问号 ...

  2. CCF-201512-3 绘图

    问题描写叙述 用 ASCII 字符来绘图是一件有趣的事情.并形成了一门被称为 ASCII Art 的艺术.比如,下图是用 ASCII 字符画出来的 CSPRO 字样. .._._.._.._-_.. ...

  3. 详解Android中那些酷炫返回方式的实现

    Android手机都会有返回键,不管是实体键,还是虚拟键.Android用户主要也都是通过这个返回键操控页面返回方式的,不比IOS逼格甚高的只保留一个操作键.这种方式是最普遍的返回方式,还有一种也是比 ...

  4. 在项目中增加自定义icon图标

    以MUI框架为例,内容来自于MUI官网. mui如何增加自定义icon图标 mui框架遵循极简原则,在icon图标集上也是如此,mui仅集成了原生系统中最常用的图标:其次,mui中的图标并不是图片,而 ...

  5. 机器学习实战笔记7(Adaboost)

    1:简单概念描写叙述 Adaboost是一种弱学习算法到强学习算法,这里的弱和强学习算法,指的当然都是分类器,首先我们须要简介几个概念. 1:弱学习器:在二分情况下弱分类器的错误率会低于50%. 事实 ...

  6. PT100三线制恒流源接法

    http://www.eepw.com.cn/article/189480_2.htm 下图为恒流源激励的三线制Pt100的一种典型接法.其基本原理是假设Pt100的三条引线采用相同长度的同型线缆,具 ...

  7. MySQL监控脚本

    zabbix监控mysql时自定key用到的脚本 #!/usr/bin/env python #-*- coding: UTF-8 -*- from __future__ import print_f ...

  8. unity, unlit surface shader (texColor only surface shader)

    要实现双面透明无光照只有纹理色的surface shader. 错误的写法:(导致带有曝光) Shader "Custom/doubleFaceTranspTexColor" { ...

  9. Atitit JAVA p2p设计与总结  JXTA 2

    Atitit JAVA p2p设计与总结  JXTA 2 JXTA 2 是开放源代码 P2P 网络的第二个主要版本,它利用流行的.基于 Java 的参考实现作为构建基础.在设计方面进行了重要的修改,以 ...

  10. zookeeper程序员指南

    1 简介本文是为想要创建使用ZooKeeper协调服务优势的分布式应用的开发者准备的.本文包含理论信息和实践信息.本指南的前四节对各种ZooKeeper概念进行较高层次的讨论.这些概念对于理解ZooK ...