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 ...
随机推荐
- LoadRunner访问Mysql数据库(转)
这是很久以前编写的一个测试案例,那时是为了检查大量往Mysql数据库里插入数据,看一下数据库的性能如何?服务器是否会很快就被写满了. 前期的准备工作:Mysql 数据库搭建,LoadRunner,li ...
- 说说iDempiere = OSGi + ADempiere的OSGi
怀揣着为中小企业量身定做一整套开源软件解决方案的梦想开始了一个网站的搭建.http://osssme.org/ 我对iDempiere还完全摸不着头脑,正好在学习之际,应erp100的@纵横四海 邀请 ...
- [转]SIGPIPE信号
我写了一个服务器程序,在Linux下测试,然后用C++写了客户端用千万级别数量的短链接进行压力测试. 但是服务器总是莫名退出,没有core文件. 最后问题确定为, 对一个对端已经关闭的socket调 ...
- linux sudo命令详解
--sudo命令重启网卡 sudo service network restart http://bestchenwu.iteye.com/blog/1450292
- 比较R语言、perl语言,matlab中for循环和while循环的使用
http://zhan.renren.com/zxccshkbx?gid=3602888498030523562&from=post&checked=true
- (转)ASP.NET MVC:Razor 引入命名空间
页面中引用 c# @using MvcApplication83.Models @using MvcApplication83.Common 行尾不需要加分号,加上也无妨(不过得全加上). VB.Ne ...
- selenium2.0 --常用函数2
新建实例driver = webdriver.Chrome() 1.获取当前页面的Url函数 方法:current_url 实例: driver.current_url 2.获取元素坐标 方法:loc ...
- STL容器分析--set
STL 对这个序列可以进行查找,插入删除序列中的任意一个元素,而完成这些操作的时间同这个序列中元素个数的对数成比例关系,并且当游标指向一个已删除的元素时,删除操作无效.而一个经过更正的和更加实际的定义 ...
- Kafka 快速起步
Kafka 快速起步 原创 2017-01-05 杜亦舒 性能与架构 性能与架构 性能与架构 微信号 yogoup 功能介绍 网站性能提升与架构设计 主要内容:1. kafka 安装.启动2. 消息的 ...
- 双线机房双网卡双ip 路由设置
做互联网网站,最头疼的事情之一就是电信和网通的互联互不通了,为了能够让北方网通和南方电信用户都可以快速的访问网站,解决办法就是托管 到双线机房.双线机房有两类,一类是通过BGP技术实现互联互通,服务器 ...