[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..
[MySQL] 페이징 시 쿼리(LIMIT, OFFSET)
2023. 9. 11. 20:37
프로그래밍/SQL
LIMIT 숫자 첫 번째부터 n개의 행 SELECT * FROM sample LIMIT 10; LIMIT 숫자 OFFSET 숫자 LIMIT : 출력할 행의 수 OFFSET : 몇 번째 행부터 출력할 지 -- 1번째 행부터 10행 출력 SELECT * FROM sample LIMIT 10 OFFSET 0 -- 3번째 행부터 5행 출력 SELECT * FROM sample LIMIT 5 OFFSET 2 LIMIT 숫자1, 숫자2 숫자1 : 몇 번째 행부터 출력할 지 숫자2 : 출력할 행의 수 -- 1번째 행부터 10행 출력 SELECT * FROM sample LIMIT 0, 10
[React] Get 파라미터로 List 전달
2023. 9. 8. 20:40
프로그래밍/React
리액트에서 스프링부트로 Get 요청 시 List를 파라미터로 전달 Aixos를 사용하여 Get 요청 시 파라미터로 List를 전달하려면 join(',')로 구분하여 전달하면 됨 예시 const idList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; const resultList = axios.get('id/list', {params: {idList: idList.join(',')}}); 위의 파라미터를 전달하는 경우 스프링에서는 idList 타입으로 받을 수 있음 controller 예시 @GetMapping("/id/list") public List getIdList(@RequestParam("idList") List idList) throws Exception { return bo..
[MySQL] ROW 문자열 합치기 (GROUP_CONCAT)
2023. 9. 7. 20:12
프로그래밍/SQL
GROUP_CONCAT GROUP BY 로 문자열을 합치는 경우 사용 기본형 GROUP_CONCAT(필드명) 구분자 변경 GROUP_CONCAT(필드명 SEPARATOR '구분자') 중복 제거 GROUP_CONCAT(DISTINCT 필드명) 문자열 정렬 GROUP_CONCAT(필드명 ORDER BY 필드명) 참고 자료 : https://fruitdev.tistory.com/16
[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 ..
[Javascript] 배열을 문자열로 합치기
2023. 8. 24. 20:18
프로그래밍/JavaScript
배열을 문자열로 합치는 방법 1. join() 배열을 하나의 문자열로 리턴 받을 때 구분값을 줄 수 있음 const arr = new Array('하나', '둘', '셋'); console.log(arr.join());// 하나,둘,셋 console.log(arr.join(''));// 하나둘셋 console.log(arr.join(' '));// 하나 둘 셋 console.log(arr.join(', '));// 하나, 둘, 셋 console.log(arr.join('-'));// 하나-둘-셋 2. toString() 콤마(,)로 구분된 하나의 문자열 리턴 const arr = new Array('하나', '둘', '셋'); console.log(arr.toString());// 하나,둘,셋
[React] Module not found... 에러 해결 방법
2023. 8. 23. 20:17
프로그래밍/React
발생 에러 Module not found: Error: You attempted to import ../../../public/assets/css/login.css which falls outside of the project src/ directory. Relative imports outsde of src/ are not supported. You can either move it inside src/, or add a symlink to it from project's node_moules/. 에러 원인 create-react-app(CRA)에서 컴파일은 src 내부에서만 일어나는데, 이때 js에서 import 된 이미지와 같이 엮여 있는 파일들은 모두 컴파일 대상임 따라서 해당 파일을 js 파일에..

[Spring Boot Error] Syntax error in SQL statement "drop table if exists [*]user cascade "; expected "identifier"; SQL statement: 에러 해결 방법
2023. 8. 21. 20:41
프로그래밍/Spring Boot
user entity 작성 후 Run 했더니 해당 에러 발생 발생 원인 user는 대부분의 데이터 베이스에서 예약어로 사용됨 그렇기에 user를 테이블 이름 등의 식별자로 사용하는 경우 에러가 발생할 수 있음 해결 방법 2가지 1. 테이블 명을 user 대신 member로 변경 2. user 테이블을 그대로 사용하고 싶다면 entity에 아래와 같은 Table 어노테이션 사용하기 @Table(name = "\"user\"")