Skip to content

Commit

Permalink
fix URLUtil doc
Browse files Browse the repository at this point in the history
  • Loading branch information
looly committed Aug 22, 2019
1 parent 8c2ecdc commit 4428add
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 0 additions & 1 deletion docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
* [引用工具-ReferenceUtil](core/工具类/引用工具-ReferenceUtil.md)
* [正则工具-ReUtil](core/工具类/正则工具-ReUtil.md)
* [身份证工具-IdcardUtil](core/工具类/身份证工具-IdcardUtil.md)
* 语言特性
* 语言特性
* [概述](core/语言特性/概述.md)
* [HashMap扩展-Dict](core/语言特性/HashMap扩展-Dict.md)
Expand Down
20 changes: 19 additions & 1 deletion docs/core/工具类/URL工具-URLUtil.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,26 @@ URL(Uniform Resource Locator)中文名为统一资源定位符,有时也

### 其它

- `URLUtil.formatUrl` 格式化URL链接。对于不带http://头的地址做简单补全。
- `URLUtil.normalize` 标准化化URL链接。对于不带http://头的地址做简单补全。

```java
String url = "http://www.hutool.cn//aaa/bbb";
// 结果为:http://www.hutool.cn/aaa/bbb
String normalize = URLUtil.normalize(url);

url = "http://www.hutool.cn//aaa/\\bbb?a=1&b=2";
// 结果为:http://www.hutool.cn/aaa/bbb?a=1&b=2
normalize = URLUtil.normalize(url);
```

- `URLUtil.encode` 封装`URLEncoder.encode`,将需要转换的内容(ASCII码形式之外的内容),用十六进制表示法转换出来,并在之前加上%开头。

```java
String body = "366466 - 副本.jpg";
// 结果为:366466%20-%20%E5%89%AF%E6%9C%AC.jpg
String encode = URLUtil.encode(body);
```

- `URLUtil.decode` 封装`URLDecoder.decode`,将%开头的16进制表示的内容解码。
- `URLUtil.getPath` 获得path部分 URI -> http://www.aaa.bbb/search?scope=ccc&q=ddd PATH -> /search
- `URLUtil.toURI` 转URL或URL字符串为URI。

0 comments on commit 4428add

Please sign in to comment.