【spring】spirng中的常用工具類

來源:互聯網
上載者:User

標籤:extract   number   res   列印   stopwatch   loader   custom   etc   vfs   

一、概述

  很多時候,很多工具類其實spring中就已經提供,常用的工具類有:

    參考:https://www.cnblogs.com/langtianya/p/3875103.html

  內建的resouce類型
    UrlResource
    ClassPathResource
    FileSystemResource
    ServletContextResource
    InputStreamResource
    ByteArrayResource
    EncodedResource 也就是Resource加上encoding, 可以認為是有編碼的資源
    VfsResource(在jboss裡經常用到, 相應還有 工具類 VfsUtils)
    org.springframework.util.xml.ResourceUtils 用於處理表達資源字串首碼描述資源的工具. 如: "classpath:".
    有 getURL, getFile, isFileURL, isJarURL, extractJarFileURL

  工具類
    org.springframework.core.annotation.AnnotationUtils

        處理註解
    org.springframework.core.io.support.PathMatchingResourcePatternResolver

        用 於處理 ant 匹配風格(com/*.jsp, com/*/.jsp),找出所有的資源, 結合上面的resource的概念一起使用
    org.springframework.core.io.support.PropertiesLoaderUtils

        載入Properties資源工具類,和Resource結合
    org.springframework.core.BridgeMethodResolver

        橋接方法分析器.
    org.springframework.core.GenericTypeResolver

        範型分析器, 在用於對範型方法, 參數分析.
    org.springframework.core.NestedExceptionUtils

  xml工具
    org.springframework.util.xml.AbstractStaxContentHandler
    org.springframework.util.xml.AbstractStaxXMLReader
    org.springframework.util.xml.AbstractXMLReader
    org.springframework.util.xml.AbstractXMLStreamReader
    org.springframework.util.xml.DomUtils
    org.springframework.util.xml.SimpleNamespaceContext
    org.springframework.util.xml.SimpleSaxErrorHandler
    org.springframework.util.xml.SimpleTransformErrorListener
    org.springframework.util.xml.StaxUtils
    org.springframework.util.xml.TransformerUtils

  其它工具集
    org.springframework.util.xml.AntPathMatcher

        ant風格的處理
    org.springframework.util.xml.AntPathStringMatcher
    org.springframework.util.xml.Assert

        斷言,在我們的參數判斷時應該經常用
    org.springframework.util.xml.CachingMapDecorator
    org.springframework.util.xml.ClassUtils

        用於Class的處理
    org.springframework.util.xml.CollectionUtils

        用於處理集合的工具
    org.springframework.util.xml.CommonsLogWriter
    org.springframework.util.xml.CompositeIterator
    org.springframework.util.xml.ConcurrencyThrottleSupport
    org.springframework.util.xml.CustomizableThreadCreator
    org.springframework.util.xml.DefaultPropertiesPersister
    org.springframework.util.xml.DigestUtils

        摘要處理, 這裡有用於md5處理資訊的
    org.springframework.util.xml.FileCopyUtils

        檔案的拷貝處理, 結合Resource的概念一起來處理, 真的是很方便
    org.springframework.util.xml.FileSystemUtils
    org.springframework.util.xml.LinkedCaseInsensitiveMap
        key值不區分大小寫LinkedMap
    org.springframework.util.xml.LinkedMultiValueMap

      一個key可以存放多個值的LinkedMap
    org.springframework.util.xml.Log4jConfigurer

      一個log4j的啟動載入指定配製檔案的工具類
    org.springframework.util.xml.NumberUtils

      處理數位工具類, 有parseNumber 可以把字串處理成我們指定的數字格式, 還支援format格式,     convertNumberToTargetClass 可以實現Number類型的轉化.
    org.springframework.util.xml.ObjectUtils

      有很多處理null object的方法. 如nullSafeHashCode, nullSafeEquals, isArray, containsElement, addObjectToArray, 等有用的方法
    org.springframework.util.xml.PatternMatchUtils

      spring裡用於處理簡單的匹配. 如 Spring‘s typical "xxx", "xxx" and "xxx" pattern styles
    org.springframework.util.xml.PropertyPlaceholderHelper

      用於處理預留位置的替換
    org.springframework.util.xml.ReflectionUtils

      反映常用工具方法. 有 findField, setField, getField, findMethod, invokeMethod等有用的方法
    org.springframework.util.xml.SerializationUtils

      用於java的序列化與還原序列化. serialize與deserialize方法
    org.springframework.util.xml.StopWatch

      一個很好的用於記錄執行時間的工具類, 且可以用於任務分階段的測試時間. 最後支援一個很好看的列印格式. 這個類應該經常用
    org.springframework.util.xml.StringUtils
    org.springframework.util.xml.SystemPropertyUtils
    org.springframework.util.xml.TypeUtils

        用於類型相容的判斷. isAssignable
    org.springframework.util.xml.WeakReferenceMonitor

        弱引用的監控

  和web相關的工具
    org.springframework.web.util.CookieGenerator
    org.springframework.web.util.HtmlCharacterEntityDecoder
    org.springframework.web.util.HtmlCharacterEntityReferences
    org.springframework.web.util.HtmlUtils
    org.springframework.web.util.HttpUrlTemplate
        這個類用於用字串模板構建url, 它會自動處理url裡的漢字及其它相關的編碼. 在讀取別人提供的url資源時, 應該經常用
        String url = "http://localhost/myapp/{name}/{id}";
    org.springframework.web.util.JavaScriptUtils
    org.springframework.web.util.Log4jConfigListener
        用listener的方式來配製log4j在web環境下的初始化
    org.springframework.web.util.UriTemplate
    org.springframework.web.util.UriUtils

        處理uri裡特殊字元的編碼
    org.springframework.web.util.WebUtils

二、使用執行個體

  1.DigestUtils ——用於MD5加密

【spring】spirng中的常用工具類

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.