1 // address格式:"192.131.2.33:7896" 2 public void parseRedisAddress(String address) { 3 this.host = RedisConfig.DEFAULT_HOST; 4 this.port = RedisConfig.DEFAULT_PORT; 5 6 if (StringUtils.isBlank(address)) { 7 return; 8 } 9 10 String[] ipAndPort = address.split(":"); 11 if (ipAndPort.length != 2) { 12 throw new RuntimeException("..."); 13 } 14 15 this.host = ipAndPort[0]; 16 // parseInt()解析失败会抛出NumberFormatException运行时异常 17 this.port = Integer.parseInt(ipAndPort[1]); 18 }
标签:String,处理,ipAndPort,DEFAULT,address,parseInt,异常,port From: https://www.cnblogs.com/woaiheniunai/p/16843001.html