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 ...
随机推荐
- Windows下如何安装 Composer
如何安装 Composer Windows下如何安装 Composer 下载 Composer 安装前请务必确保已经正确安装了 PHP.打开命令行窗口并执行 php -v 查看是否正确输出版本号. 打 ...
- 禁止chrome自动更新
删除C:\Program Files (x86)\Google文件夹下面的updata文件夹
- POJ2406-Power Strings(kmp循环节)
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 31111 Accepted: 12982 D ...
- Mybatis <if>标签
格式:<if test=""> sql语句 </if> <select id="selectByName" resultType= ...
- bootstrap学习笔记一 登录水平表单
先上效果图: 样式定义: <form class="form-horizontal"> <div class="control-group"& ...
- C# EF更新当前实体报错 ObjectManager无法管理具有相同键值的多个对象
原因: ObjectManager已经在跟踪此对象 更新实体前判断 if (db.Entry<T>(t).State != EntityState.Modified) db.Entry&l ...
- symbolicatecrash 使用方法
symbolicatecrash 使用方法 1-找到symbolicatecrash find /Applications/Xcode.app -name symbolicatecrash -type ...
- NOIP2007:纪念品分组
#include<stdio.h> #include<stdlib.h> int a[100]; int main(){ int i,j,k,m,n,w; scanf(&quo ...
- HIVE的transform函数的使用
Hive的TRANSFORM关键字提供了在SQL中调用自写脚本的功能,适合实现Hive中没有的功能又不想写UDF的情况.例如,按日期统计每天出现的uid数,通常用如下的SQL SELECT date, ...
- nginx-1.2.7+tcp_proxy_module负载均衡配置
对于安装方面不清楚的,可移步 nginx + tcp_proxy_module的安装 参考nginx_tcp_proxy_module的readme文件,对每个定义项都做了详细的描述,tcp{...} ...