예전에 Spring에서 파일 업로드 하는 방법을 올린 적이 있었는데([Spring] Spring으로 파일 업로드하기.), 이번엔 조금 더 간편한 방법으로 올린다. import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import org.apache.commons.io.FileUtils; import org.springframework.web.multipart.MultipartFile; public class FileUtils { // 파일업로드 public static void upload(List multipartFileList) throws Exception { try { ..
1. fetch를 사용한 이유 jquery ajax를 사용하지 않고(바닐라 자바스크립트 지향) 비동기 호출을 할 수 있는 방법을 찾던 중, 원시적인 XMLHttpRequest를 사용하는 방법과 fetch API를 사용하는 방법 대략 두 가지가 있음을 알게 되었다. XMLHttpRequest의 경우 브라우저별로 객체 생성을 달리해야 하는 번거로움이 있다. 그래서 나온 게 ajax. 그러나 난 jquery를 기반으로 하는 ajax를 쓰고 싶지 않다! 고로 XMLHttpRequest에 비해 브라우저 호환성 걱정할 필요없고 사용법도 간단한 fetch를 선택했다. 아래는 실제 프로젝트에 사용한 예제다. 2. 예제 /** * 비동기 호출 함수 (POST-일반) * @param {string} url 비동기 호출할 ..
1. build.gradle compile "org.springframework.data:spring-data-redis:1.8.23.RELEASE" compile "redis.clients:jedis:2.9.3" 2. 빈 설정 추가 3. Controller.java 사용 예제 import org.springframework.data.redis.core.RedisTemplate; @Autowired private RedisTemplate redisTemplate; // 데이터 저장 HashMap dateMap = new HashMap(); dateMap.put("email", "aaa@abc.co.kr"); dateMap.put("mobile", "12341234"); redisTemplate.opsFo..
1. Redis 설치 yum install redis 2. Redis 시작 및 재부팅 시 시작 설정 systemctl start redis systemctl enable redis 3. 잘되는지 확인 redis-cli ping >> PONG 4. Redis 설정 vi /etc/redis.conf # 기존 설정값 주석처리 #bind 127.0.0.1 # 로컬호스트만 접속 가능 -> 모든 호스트에서 접속 가능하도록 수정 bind 0.0.0.0 # port 수정 port 1234 # 비밀번호 설정 requirepass password1234 5. 서비스 재시작 systemctl restart redis 6. 레디스 외부에서 접속 가능하게 설정이 잘 되었는지 확인 netstat -nlpt | grep 1234 ..
일하면서 사용한 java stream 몇 가지 예제들을 기록해둔다. import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; public class StreamFilter01 { public static void..
동적으로 다른 클래스의 메서드와 필드값을 불러와서 사용해야 하는 경우, Java Reflection을 활용하면 가능하다. // 메서드------------------------------------------------------------------------- Method getSomethingMethod = ClassName.getClass().getDeclaredMethod("getSomething", String.class); getSomethingMethod.setAccessible(true); // private 함수 접근 허용. String someString = (String) getSomethingMethod.invoke("something"); // 불러올 메서드가 static일 때...