Spring工具类
文件资源访问
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工具类的更多相关文章
- spring 工具类大集合
接以前的文章 apache-commons 常用工具类 和文章 apache-commons 工具类扩展 小家 Spring 对 spring 的工具类做了详细的介绍(一) 这里我抽出一些好用的类,不 ...
- Spring工具类 非spring管理环境中获取bean及环境配置
SpringUtils.java import org.springframework.beans.BeansException; import org.springframework.beans.f ...
- Spring工具类:WebApplicationContextUtils
当 Web 应用集成 Spring 容器后,代表 Spring 容器的WebApplicationContext对象将以 WebApplicationContext.ROOT_WEB_APPLICAT ...
- JDBC JdbTemplate&NamedParameterJdbcTemplate(Spring工具类)
使用该工具类需要从spring开发包中导入spring.jar和commons-logging.jar,这个模板是线程安全的. JdbcTemplate: public class JdbcTem ...
- spring工具类获取bean
import org.springframework.web.context.ContextLoader; import org.springframework.web.context.WebAppl ...
- 借助Spring工具类如何实现支持数据嵌套的赋值操作
假设有两个Bean A和B,想将B中的属性赋值到A实体中,可以使用get set来实现,当属性过多时,就会显得很冗余,可以使用spring提供的BeanUtils.copyProperties()来实 ...
- 你可能用到的Spring工具类?
现在绝大部分项目都已经拥抱Spring生态,掌握Spring常用的工具类,是非常重要,零成本增加编码效率. 一.常用工具类 ObjectUtils org.springframework.util.O ...
- Spring工具类ToStringBuilder用法简介
比如说我们需要打印某个方法的User参数对象 package test; /** * * @author zhengtian * @time 2012-6-28 */ public class Use ...
- 通过spring工具类获取bean
package xxx; import org.springframework.beans.BeansException; import org.springframework.beans.facto ...
随机推荐
- vb.net小试三层架构
在对三层架构有了初步了解后,用vb.net做了一个小的程序,真的很小,仅仅是为了体现一下三层之间机制.下面是我设计的操作界面: 还有程序集和类的分布情况, 接下来是数据的设计,数据库用到的是SQL S ...
- Openerp开发进销存系统总结
转自 :http://blog.sina.com.cn/s/blog_7cb52fa80101ngt8.html 差不多用了2个星期的闲余事件,对于openerp v7.0进行了学习和应用开发.细节总 ...
- Android so文件生成
http://blog.csdn.net/laczff21/article/details/7542236 http://blog.csdn.net/yhm2046/article/details/8 ...
- [IOS A] - 一些开源类库
因 为iOS SDK相对比较底层,所以开发者就得受累多做一些体力活.不过幸运的是,有很多第三方的类库可以用来简化很多不必要的工作.笔者整理了一下在本人学习过程 中用到的一些比较有用Objective- ...
- Cannot make a static reference to the non-static method的解决方法
报错原因:在一个类中写了一个public String getContent()方法和一个main()方法,getContent()方法中包含了getClass()方法,在main()方法中直接调用了 ...
- php中数据类型自动转换
1.1 转为布尔型(即返回值为0) 空字符串''或"" 数字0或0.0 字符'0'或"0" 空值NULL 没有成员的数组 其余都转换成布尔型true,包含 ...
- C# OO(初级思想)
继承,多态,封装 在C#中,为了能够合理描述自然界的规律,面向对象的编程引入了继承的概念,是面向对象编程中最重要的概念之一,定义了如何根据现有的类创建新类的过程. 继承:一个类派生出来的子类具有这个类 ...
- FreeMarker静态化文件解决SEO推广问题
1.问题背景 SEO一直是站点对外推广的一个重要手段,如何可以让搜索引擎高速搜索到站点对于增强站点的浏量,提升站点对外形象有着重要意义.那么如何可以对SEO进行优化呢?一个很经常使用的手段就是在网页的 ...
- Spring技术内幕:Spring AOP的实现原理(三)
生成SingleTon代理对象在getSingleTonInstance方法中完毕,这种方法时ProxyFactoryBean生成AopProxy对象的入口.代理对象会封装对target目标对象的调用 ...
- 转 OAuth 2.0授权协议详解
http://www.jb51.net/article/54948.htm 作者:阮一峰 字体:[增加 减小] 类型:转载 时间:2014-09-10我要评论 这篇文章主要介绍了OAuth 2.0授权 ...