日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java开发中spring常用的工具类

發布時間:2024/7/23 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java开发中spring常用的工具类 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

內置的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的概念一起使用,對于遍歷文件很有用. 具體請詳細查看javadoc
  • org.springframework.core.io.support.PropertiesLoaderUtils 加載Properties資源工具類,和Resource結合
  • org.springframework.core.BridgeMethodResolver 橋接方法分析器. 關于橋接方法請參考: http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.12.4.5
  • 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.AntPathMatcherant風格的處理
  • 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.PatternMatchUtilsspring里用于處理簡單的匹配. 如 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
  • org.springframework.web.util.
  • 請求工具類 org.springframework.web.bind.ServletRequestUtils
  • //取請求參數的整數值:

    public static Integer getIntParameter(ServletRequest request, String name)

    public static int getIntParameter(ServletRequest request, String name, int defaultVal) -->單個值

    public static int[] getIntParameters(ServletRequest request, String name) -->數組

    還有譬如long、float、double、boolean、String的相關處理方法。

  • 字符串工具類 org.springframework.util.StringUtils
  • 首字母大寫: public static String capitalize(String str)

    首字母小寫:public static String uncapitalize(String str)

    判斷字符串是否為null或empty: public static boolean hasLength(String str)

    判斷字符串是否為非空白字符串(即至少包含一個非空格的字符串):public static boolean hasText(String str)

    獲取文件名:public static String getFilename(String path) 如e.g. "mypath/myfile.txt" -> "myfile.txt"

    獲取文件擴展名:public static String getFilenameExtension(String path) 如"mypath/myfile.txt" -> "txt"

    還有譬如數組轉集合、集合轉數組、路徑處理、字符串分離成數組、數組或集合合并為字符串、數組合并、向數組添加元素等。

  • 對象序列化與反序列化 org.springframework.util.SerializationUtils
  • public static byte[] serialize(Object object)

    public static Object deserialize(byte[] bytes)

  • 數字處理 org.springframework.util.NumberUtils
  • 字符串轉換為Number并格式化,包括具體的Number實現類,如Long、Integer、Double,字符串支持16進制字符串,并且會自動去除字符串中的空格:

    ? public static <T extends Number> T parseNumber(String text, Class<T> targetClass)

    ? public static <T extends Number> T parseNumber(String text, Class<T> targetClass, NumberFormatnumberFormat)

    各種Number中的轉換,如Long專為Integer,自動處理數字溢出(拋出異常):

    public static <T extends Number> T convertNumberToTargetClass(Number number, Class<T> targetClass)

  • 文件復制 org.springframework.util.FileCopyUtils
  • 流與流之間、流到字符串、字節數組到流等的復制

  • 目錄復制 org.springframework.util.FileSystemUtils
  • 遞歸復制、刪除一個目錄

  • MD5加密 org.springframework.util.DigestUtils
  • 字節數組的MD5加密 public static String md5DigestAsHex(byte[] bytes)

    為了讓學習變得輕松、高效,今天給大家免費分享一套Java入門教學資源。幫助大家在成為Java架構師的道路上披荊斬棘。需要入門的資料歡迎加入學習交流群:9285,05736

    總結

    以上是生活随笔為你收集整理的java开发中spring常用的工具类的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。