[Spring Error] java.lang.IllegalArgumentException: Invalid character found in the request target... 에러 해결 방법
2023. 12. 1. 20:58
프로그래밍/JAVA
java.lang.IllegalArgumentException: Invalid character found in the request target. 에러 프론트에서 파일명을 백엔드로 넘길 때 해당 에러가 발생 발생 원인 파일명에 특수 문자나 공백을 포함하고 있어서 에러 발생 해결 방법 파일명을 인코딩해서 서버로 보내기 예시 const data = encodeURI("home/dev/[20231201]샘플_첨부_파일.png");
[Java] ArrayList 맨 앞에 값 추가하기
2023. 10. 12. 20:50
프로그래밍/JAVA
ArrayList 맨 앞에 값 추가하기 addAll을 사용하여 0번째 인덱스에 값 추가 import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Sample { public static void main(String[] args) { List list1 = new ArrayList(Arrays.asList("3", "4")); List list2 = new ArrayList(Arrays.asList("1", "2")); // list 맨 앞에 값 추가 => 0번째 인덱스에 값 추가 list1.addAll(0, list2); // 결과 출력 System.out.println(list1); // [1, 2,..
[Java] Deprecated StringUtils.isEmpty 대체
2023. 9. 27. 20:28
프로그래밍/JAVA
StringUtils.isEmpty 대체 StringUtils.isEmpty가 deprecated 됨 hasLength, hasText로 대체해서 사용 가능 StringUtils.hasLength 문자열의 길이 확인 주어진 문자열이 null이 아니고 길이가 0보다 크면 true String str = "Hello, World!"; boolean hasLength = StringUtils.hasLength(str); StringUtils.hasText 문자열에 공백 문자를 제외한 실제 문자가 포함되어 있는지 확인 주어진 문자열이 null이 아니고 길이가 0보다 크며, 공백 문자를 제외한 문자가 포함되어 있으면 ture String str = " "; boolean hasText = StringUtils.h..
[Java] 자료형 비교
2023. 9. 14. 20:12
프로그래밍/JAVA
주소값 비교 (== 연산자) == 연산자는 두 개의 변수나 객체의 메모리 주소값을 비교 두 변수가 같은 객체를 참조할 때만 true를 반환하며, 객체의 내용이 같은지 여부와는 관계 없음 객체가 동일한 인스턴스인 경우에만 == 비교는 true를 반환 String str1 = new String("Hello"); String str2 = new String("Hello"); System.out.println(str1 == str2); // false (서로 다른 객체의 주소값을 비교) 값 비교 (equals 메서드) 두 객체의 내용이 같은지 비교 객체의 내용, 즉 데이터가 동일한 경우 true를 반환하며, 객체의 메모리 주소값과는 상관없음 equals 메서드는 일반적으로 클래스에서 재정의(override)되..
[Java] String을 Integer로 변환(String to Integer, String to Long)
2023. 9. 13. 20:46
프로그래밍/JAVA
String을 Integer 혹은 String을 Long으로 변환하기 예시 String value = "10000"; Integer integerValue = Integer.parseInt(value); Long longValue = Long.parseLong(value); String에 null 혹은 빈 값이 들어갈 수 있다면 꼭 예외처리 해주기 String value = ""; Integer integerValue = value != null && !value.isEmpty() ? Integer.parseInt(value) : null; Long longValue = value != null && !value.isEmpty() ? Long.parseLong(value) : null;
[Java] NULL 처리 방법
2023. 9. 12. 20:42
프로그래밍/JAVA
StringUtils.isEmpty null 이나 "" 이면 true 반환 StringUtils.isEmpty(null); // true StringUtils.isEmpty(""); // true StringUtils.isEmpty("value"); // false StringUtils.isEmpty(" "); // false StringUtils.isNotEmpty null 이나 "" 이면 false 반환 StringUtils.isNotEmpty(null); // false StringUtils.isNotEmpty(""); // false StringUtils.isNotEmpty("value"); // true StringUtils.isNotEmpty(" "); // true StringUtils.is..
[Java] LocalDateTime 값을 yyyyMMdd 문자열로 포맷팅
2023. 9. 5. 20:04
프로그래밍/JAVA
LocalDateTime을 문자열로 포맷팅 String formatDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); System.out.println(formatDate);// 20230904 참고 자료 : https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html DateTimeFormatter (Java Platform SE 8 ) Parses the text using this formatter, without resolving the result, intended for advanced use cases. Parsing is ..
[Java] 특정 파일 찾아서 가져오기
2023. 8. 2. 20:02
프로그래밍/JAVA
특정 경로의 파일, 특정된 파일명으로 파일 찾아오는 방법 특정 경로의 파일을 가져와서 읽어야하는 플젝을 한 적이 있어 그 방법을 공유하고자 작성함 내 경우 폴더 경로를 찾는데 좀 복잡한 조건이 있었음 /Users 폴더 안에 하위로 이름이 다 다른 폴더들이 있고, 그 폴더가 몇개가 될지는 모르지만 최하위 폴더로 Downloads/sample 폴더가 존재하는 폴더를 찾아서 그 안의 sample1.txt, sample2.txt만 찾아서 읽어야 했음 내가 읽어야 하는 정보는 아래의 사진과 같이 /Users 폴더안에 있는 /Downloads/sample/sample1.txt, sample2.txt 이 두 파일이였음 해당 경로의 파일 찾아서 읽기 나는 Downloads/sample을 찾을 때 재귀함수를 통해서 계속..