mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add UrlBuilder getPortWithDefault
This commit is contained in:
parent
dca6cbe4b1
commit
311829660f
@ -291,6 +291,26 @@ public final class UrlBuilder implements Builder<String> {
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取端口,如果未自定义返回协议默认端口
|
||||
*
|
||||
* @return 端口
|
||||
*/
|
||||
public int getPortWithDefault() {
|
||||
int port = getPort();
|
||||
if (port != -1) {
|
||||
return port;
|
||||
}
|
||||
switch (this.scheme) {
|
||||
case "http":
|
||||
return 80;
|
||||
case "https":
|
||||
return 443;
|
||||
default:
|
||||
return port;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置端口,默认-1
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user