네트워크연계유틸추가
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package com.kamco.cd.kamcoback.common.utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import org.mindrot.jbcrypt.BCrypt;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
public class NetUtils {
|
||||
|
||||
public String getLocalIP(){
|
||||
|
||||
String ip;
|
||||
{
|
||||
try {
|
||||
InetAddress local = InetAddress.getLocalHost();
|
||||
ip = local.getHostAddress();
|
||||
} catch (UnknownHostException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return ip;
|
||||
}
|
||||
|
||||
|
||||
public String dtoToQueryString(Object dto, String queryString) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
// 1. DTO를 Map으로 변환
|
||||
Map<String, Object> map = objectMapper.convertValue(dto, Map.class);
|
||||
|
||||
String qStr = map.entrySet().stream()
|
||||
.filter(entry -> entry.getValue() != null) // null 제외
|
||||
.map(entry -> String.format("%s=%s",
|
||||
entry.getKey(),
|
||||
URLEncoder.encode(entry.getValue().toString(), StandardCharsets.UTF_8)))
|
||||
.collect(Collectors.joining("&"));
|
||||
|
||||
if( queryString == null || queryString.isEmpty() ) {
|
||||
queryString = "?"+qStr;
|
||||
}else{
|
||||
queryString = queryString +"&" + qStr;
|
||||
}
|
||||
|
||||
// 2. Map을 쿼리 스트링 문자열로 변환
|
||||
return queryString;
|
||||
}
|
||||
|
||||
public HttpHeaders jsonHeaders() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user