首页 > 其他分享 >spring工具类

spring工具类

时间:2023-04-17 11:07:22浏览次数:39  
标签:xml web core spring springframework util org 工具


文件资源操作:

org.springframework.core.io.Resource接口,是为了统一各种类型的资源而定义的

1.访问文件资源

org.springframework.core.io.ClassPathResource 类路径进行访问

org.springframework.core.io.FileSystemResource 文件系统的绝对路径进行访问

org.springframework.web.context.support.ServletContextResource  以相对web应用根目录进行访问

org.springframework.core.io.UrlResource url地址访问文件

org.springframework.util.ResourceUtils 支持用classpaht和file取文件而不需要直接创建Resource实现类

 

2.本地化文件资源

org.springframework.core.io.support.LocalizedResourceHelper

 

3.文件内容拷贝

org.springframework.util.FileCopyUtils

 

4.属性文件操作

org.springframework.core.io.support.EncodedResource  属性文件转码

org.springframework.core.io.support.PropertiesLoaderUtils  加载属性文件

 

web相关的工具类

1.访问spirngWebApplicationContext

org.springframework.web.context.support.WebApplicationContextUtils 

2.简化servlet操作

org.springframework.web.util.WebUtils

3.创建cookie

org.springframework.web.util.CookieGenerator

 

过滤器和监听类

1.解决请求hibernate延迟加载对象报错

org.springframework.orm.hibernate.support.OpenSessionInViewFilter

2.解决中文乱码

org.springframework.web.filter.CharacterEncodingFilter

3.Introspector缓存消除监听器

org.springframework.web.util.IntrospectorCleanupListener

 

特殊字符转义

1.html的转义

org.springframework.web.util.HtmlUtils

2.javascript的转义

org.springframework.web.util.JavaScriptUtils

 

方法参数检查类

1.org.springframework.util.Assert

 

 

spring给我们提供了很多的工具类, 应该在我们的日常工作中很好的利用起来. 它可以大大的减轻我们的平时编写代码的长度. 因我们只想用spring的工具类,

而不想把一个大大的spring工程给引入进来. 下面是我从spring3.0.5里抽取出来的工具类.

在最后给出我提取出来的spring代码打成的jar包

spring的里的resouce的概念, 在我们处理io时很有用. 具体信息请参考spring手册

内置的resouce类型

  1. UrlResource
  2. ClassPathResource
  3. FileSystemResource
  4. ServletContextResource
  5. InputStreamResource
  6. ByteArrayResource
  7. EncodedResource  也就是Resource加上encoding, 可以认为是有编码的资源
  8. VfsResource (在jboss里经常用到, 相应还有 工具类 VfsUtils)
  9. org.springframework.util.xml.ResourceUtils  用于处理表达资源字符串前缀描述资源的工具. 如: "classpath:".
    有 getURL, getFile, isFileURL, isJarURL, extractJarFileURL

工具类

  1. org.springframework.core.annotation.AnnotationUtils    处理注解
  2. org.springframework.core.io.support.PathMatchingResourcePatternResolver   用于处理 ant 匹配风格(com/*.jsp, com/**/*.jsp),找出所有的资源, 结合上面的resource的概念一起使用,对于遍历文件很有用. 具体请详细查看javadoc
  3. org.springframework.core.io.support.PropertiesLoaderUtils  加载Properties资源工具类,和Resource结合
  4. org.springframework.core.BridgeMethodResolver   桥接方法分析器.  关于桥接方法请参考: http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.12.4.5
  5. org.springframework.core.GenericTypeResolver   范型分析器, 在用于对范型方法, 参数分析.
  6. org.springframework.core.NestedExceptionUtils

xml工具

  1. org.springframework.util.xml.AbstractStaxContentHandler
  2. org.springframework.util.xml.AbstractStaxXMLReader
  3. org.springframework.util.xml.AbstractXMLReader
  4. org.springframework.util.xml.AbstractXMLStreamReader
  5. org.springframework.util.xml.DomUtils
  6. org.springframework.util.xml.SimpleNamespaceContext
  7. org.springframework.util.xml.SimpleSaxErrorHandler
  8. org.springframework.util.xml.SimpleTransformErrorListener
  9. org.springframework.util.xml.StaxUtils
  10. org.springframework.util.xml.TransformerUtils


其它工具集

  1. org.springframework.util.xml.AntPathMatcher ant风格的处理
  2. org.springframework.util.xml.AntPathStringMatcher
  3. org.springframework.util.xml.Assert 断言,在我们的参数判断时应该经常用
  4. org.springframework.util.xml.CachingMapDecorator
  5. org.springframework.util.xml.ClassUtils 用于Class的处理
  6. org.springframework.util.xml.CollectionUtils 用于处理集合的工具
  7. org.springframework.util.xml.CommonsLogWriter
  8. org.springframework.util.xml.CompositeIterator
  9. org.springframework.util.xml.ConcurrencyThrottleSupport
  10. org.springframework.util.xml.CustomizableThreadCreator
  11. org.springframework.util.xml.DefaultPropertiesPersister
  12. org.springframework.util.xml.DigestUtils 摘要处理, 这里有用于md5处理信息的
  13. org.springframework.util.xml.FileCopyUtils 文件的拷贝处理, 结合Resource的概念一起来处理, 真的是很方便
  14. org.springframework.util.xml.FileSystemUtils
  15. org.springframework.util.xml.LinkedCaseInsensitiveMap
    key值不区分大小写的LinkedMap
  16. org.springframework.util.xml.LinkedMultiValueMap 一个key可以存放多个值的LinkedMap
  17. org.springframework.util.xml.Log4jConfigurer 一个log4j的启动加载指定配制文件的工具类
  18. org.springframework.util.xml.NumberUtils 处理数字的工具类, 有parseNumber 可以把字符串处理成我们指定的数字格式, 还支持format格式, convertNumberToTargetClass 可以实现Number类型的转化.
  19. org.springframework.util.xml.ObjectUtils 有很多处理null object的方法. 如nullSafeHashCode, nullSafeEquals, isArray, containsElement, addObjectToArray, 等有用的方法
  20. org.springframework.util.xml.PatternMatchUtils spring里用于处理简单的匹配. 如 Spring's typical "xxx*", "*xxx" and "*xxx*" pattern styles
  21. org.springframework.util.xml.PropertyPlaceholderHelper 用于处理占位符的替换
  22. org.springframework.util.xml.ReflectionUtils 反映常用工具方法. 有 findField, setField, getField, findMethod, invokeMethod等有用的方法
  23. org.springframework.util.xml.SerializationUtils 用于java的序列化与反序列化. serialize与deserialize方法
  24. org.springframework.util.xml.StopWatch 一个很好的用于记录执行时间的工具类, 且可以用于任务分阶段的测试时间. 最后支持一个很好看的打印格式. 这个类应该经常用
  25. org.springframework.util.xml.StringUtils
  26. org.springframework.util.xml.SystemPropertyUtils
  27. org.springframework.util.xml.TypeUtils 用于类型相容的判断. isAssignable
  28. org.springframework.util.xml.WeakReferenceMonitor 弱引用的监控

和web相关的工具

  1. org.springframework.web.util.CookieGenerator
  2. org.springframework.web.util.HtmlCharacterEntityDecoder
  3. org.springframework.web.util.HtmlCharacterEntityReferences
  4. org.springframework.web.util.HtmlUtils
  5. org.springframework.web.util.HttpUrlTemplate
    这个类用于用字符串模板构建url, 它会自动处理url里的汉字及其它相关的编码. 在读取别人提供的url资源时, 应该经常用
    String url = "http://localhost/myapp/{name}/{id}"
  6. org.springframework.web.util.JavaScriptUtils
  7. org.springframework.web.util.Log4jConfigListener
    用listener的方式来配制log4j在web环境下的初始化
  8. org.springframework.web.util.UriTemplate
  9. org.springframework.web.util.UriUtils 处理uri里特殊字符的编码
  10. org.springframework.web.util.WebUtils
  11. org.springframework.web.util.

标签:xml,web,core,spring,springframework,util,org,工具
From: https://blog.51cto.com/u_16071779/6194750

相关文章

  • 笔记springboot0410
    1.课程大纲-springboot框架1.什么是Springboot以及Springboot的特点。2.快速搭建springboot项目3.springboot常用的配置文件类型.4.读取springboot配置文件的内容5.多环境配置6.springboot整合数据源。7.springboot整合mybatis.8.springboot整合定时器。2.什么......
  • spring手动开启、提交、回滚事务
    配置事务<!--(事务管理)--><beanname="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><propertyname="dataSource"ref="dataSource"/></bean>......
  • Pake 基于rust 开发的快速web 页面打包app 的工具
    Pake利用了tauri可以实现web页面快速打包桌面app说明对于希望快速打开一个桌面应用的场景,Pake还是值得试用的参考资料https://github.com/tw93/Pake......
  • SpringMVC-JSR303和拦截器
    1.JSR3031.1.什么是JSR303JSR是JavaSpecificationRequests的缩写,意思是Java规范提案。是指向JCP(JavaCommunityProcess)提出新增一个标准化技术规范的正式请求。任何人都可以提交JSR,以向Java平台增添新的API和服务。JSR已成为Java界的一个重要标准。JSR-303是JAVAEE6......
  • SpringMvc CRUD
    1.前期准备1.1.配置欢迎页在webapp下添加/home/index.html,再在WEB-INF目录下创建index.jsp(真正的欢迎页面)在web.xml中配置<welcome>标签,并加入/home/index.html<welcome-file-list><welcome-file>/home/index.html</welcome-file></welcome-file-list>通过Controller......
  • Java | 一分钟掌握JDK命令行工具 | 4 - 可视化分析工具
     作者:Mars酱 声明:本文章由Mars酱编写,部分内容来源于网络,如有疑问请联系本人。 转载:欢迎转载,转载前先请联系我!前言我们其实在分析的时候,也并不是必须使用命令行工具才能可以分析。JDK还提供了可视化工具让大家可以在图形化的操作系统中使用。可视化分析工具可视化分析工具分两种:......
  • jmeter测试工具-测试基础(2)-jmeter中如何录制脚本
    一:JMeter中录制脚本jmeter中如何录制脚本1,新建一个测试计划---添加---非测试原件---HTTP代理服务器2,在浏览器中进行设置-高级-系统-打开计算机代理设置3,如下图所示,然后启动HTTP代理服务器4,录制完毕,关闭录制,关闭代理  1,创建代理服务器:  2、添加录制控......
  • 编程语言和编程工具
    使用过的语言:C、JavaC语言的优势:C语言编写的代码效率高,运行速度快。C语言的语法和功能简单,易于学习和理解。C语言具有很高的可移植性,可以在多种不同的平台上运行。Java语言的优势:Java语言是一种跨平台的编程语言,可以在不同的操作系统和硬件平台上运行。Java语言有很多强大......
  • Spring04_Aop
    一、AOP概述(一)AOP简介​ 面向切面编程是一种通过横切关注点(Cross-cuttingConcerns)分离来增强代码模块性的方法,它能够在不修改业务主体代码的情况下,对它添加额外的行为。(二)为何需要AOP​ 面向对象编程OOP可以通过对业务的分析,然后抽象出一系列具有一定属性与行为的类,并通......
  • 关于Spring依赖注入一些理解和总结
    平常的java开发中,程序员在某个类中需要依赖其它类的方法,则通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理,spring提出了依赖注入的思想,即依赖类不由程序员实例化,而是通过spring容器帮我们new指定实例并且将实例注入到需要该对象的类中。依......