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 ...
随机推荐
- 【构建Android缓存模块】(一)吐槽与原理分析
http://my.oschina.net/ryanhoo/blog/93285 摘要:在我翻译的Google官方系列教程中,Bitmap系列由浅入深地介绍了如何正确的解码Bitmap,异步线程操作以 ...
- js取消radio选中 反选
var radio=document.createElement("input");radio.type="radio";radio.onclick = fun ...
- nginx 反向代理做域名转发简单配置
这里用的是nginx for windows 首先进入nginx配置文件,做以下配置: server { listen 80; server_name abc.com; location / { pr ...
- 强大的代码生成工具 MyGeneration
MyGeneration是一个功能很强大的代码生成工具.通过编写包含各种类型脚本(C#,VB.Net,JScript,VBScript)的模板,通过数据库的表内容,生成你需要的各种代码.你可以用它来生 ...
- bootstrap 网格系统学习
Bootstrap 官方文档中有关网格系统的描述: Bootstrap 包含了一个响应式的.移动设备优先的.不固定的网格系统,可以随着设备或视口大小的增加而适当地扩展到 12 列.它包含了用于简单的布 ...
- c#封装DBHelper类 c# 图片加水印 (摘)C#生成随机数的三种方法 使用LINQ、Lambda 表达式 、委托快速比较两个集合,找出需要新增、修改、删除的对象 c# 制作正方形图片 JavaScript 事件循环及异步原理(完全指北)
c#封装DBHelper类 public enum EffentNextType { /// <summary> /// 对其他语句无任何影响 /// </summary> ...
- 折腾docker安装笔记
最近尝试把netcore迁移到docker,然后在本地虚拟机尝试装下 发现yum安装好复杂 于是记录下 1.7.2 centos的ios装虚拟机 2.修改网络 配置文件 查看网络地址 然后xshell ...
- oracle 复杂的查找用法
[第一题]: 找到员工表中工资最高的前三名,要求按如下格式输出(第一步部分):以及oracle查询结果指定分页显示的方法(第二部分). ——涉及Top-N分析问题. 一般不在子查询中使用order b ...
- Lintcode---区间最小数
给定一个整数数组(下标由 0 到 n-1,其中 n 表示数组的规模),以及一个查询列表.每一个查询列表有两个整数 [start, end]. 对于每个查询,计算出数组中从下标 start 到 end ...
- Nodejs 命令行交互神奇 yargs
传送门: # example https://github.com/yargs/yargs/blob/master/docs/examples.md # 官网 http://yargs.js.org/ ...