본문 바로가기

전체 글155

QueryDSL 조인 예제 Inner Join QCustomer customer = QCustomer.customer; QCompany company = QCompany.company; queryFactory.select(customer.firstName, customer.lastName, company.name) .from(customer) .innerJoin(customer.company, company) .fetch(); Left Join queryFactory.select(customer.firstName, customer.lastName, company.name) .from(customer) .leftJoin(customer.company, company) .fetch(); 다음과 같이 SQL처럼 on을 사용해서 조인 조.. 2019. 6. 5.
Java 시스템 운영체제 정보 출력하기 Java 애플리케이션이 현재 동작하고 있는 시스템 운영체제 정보 출력하기 위해서는 System.getProperty("os.name") 코드를 사용하면 된다. 프로퍼티에서 가져온 정보를 기반으로 조건문을 사용해서 OS를 구분한다. public class SystemOsMain { public static void main(String[] args) { String os = System.getProperty("os.name").toLowerCase(); if (os.contains("win")) { System.out.println("Windows"); } else if (os.contains("mac")) { System.out.println("Mac"); } else if (os.contains("ni.. 2019. 6. 4.
Spring Core 라이브러리 이용해서 Properties 파일 데이터 읽기 public class Main { public static void main(String[] args) throws Exception { Resource resource = new ClassPathResource("custom.properties"); // 1 Properties properties = PropertiesLoaderUtils.loadProperties(resource); // 2 System.out.println(properties); // 3 } } 1. custom.properties 파일 데이터를 가져와서 Resource 객체로 캐스팅 2. PropertiesLoaderUtils 유틸 클래스를 이용해서 Properties 객체로 변환 3. properties 객체 내용 출력 2019. 5. 28.
Moment 타임존 값에 따라 날짜 포맷팅 출력 const today = moment().lang("ko").format('LLL'); console.log(today); 참고자료 https://momentjs.com/timezone/docs/ 2019. 5. 24.
리팩토링 - 메서드 정리 메서드 추출 (Extract Method) 어떤 코드를 그룹으로 묶어도 된다고 판단이 들면, 해당 코드들을 빼내어 목적을 잘 나타내는 메서드로 만들자 수정전 코드 public void printOwing(double previousAmount) { System.out.println("****************"); System.out.println("*****고객 외상****") System.out.println("****************"); double outstanding = previousAmount * 1.2; for (Order o : orders) { outstanding += o.getAmount(); } System.out.println("name: " + name); Syste.. 2019. 5. 16.
MySQL "Cannot get geometry object from data you send to the GEOMETRY field" 에러 해결방법 임시 테이블 생성 id, geometry 두 개의 컬럼을 구성된 테이블을 생성한다. CREATE TABLE `geo_test` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `geo` geometry DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; 테이블에 geometry 타입 데이터 추가 (에러 발생) 아래 SQL 구문을 실행하면 "Cannot get geometry object from data you send to the GEOMETRY field" 에러가 발생한다. geometry 필드에 텍스트 값을 넣으려고 했기 때문에 발생한 에러이다. INSER.. 2019. 5. 13.
LocalDateTime 값을 yyyyMMdd 문자열로 포맷팅 String formatDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); // 20190513으로 출력 System.out.println(formatDate); 참고자료 DateTimeFormatter Doc 문서 2019. 5. 13.
Python 리스트의 원소들을 2개씩 묶어서 합 구하기 자연수 N을 입력 받아서 N개의 1 이상 5 이하의 난수로 이루어진 리스트 a를 생성한다. 생성된 리스트의 원소들을 2개씩 묶어서 합을 구한 다음 새로운 리스트 b를 구하라. import random def twoSum(a, n): b = [] for i in range(0, n, 2): if (i == n-1): b.append(a[i]) else: b.append(a[i] + a[i+1]) return b; N = int(input('N = ')) a = [] # N 개수 만큼 1 이상 5 이하 난수로 이루어진 숫자 생성 for i in range(N): a.append(random.randrange(1, 6)) print('a =', a) print('b =', twoSum(a, N)) 2019. 5. 11.
Python 중복 데이터 없이 정수를 입력 받아서 소수와 비소수의 합 구하기 중복되는 데이터 없이 정수를 입력 받아서 리스트 a를 만든다. 리스트의 원소 중 비소수의 합과 소수의 합을 출력하는 함수를 작성한다. 만약 2보다 작은 수를 입력하면 안내 메시지를 출력한다. import math def isPrime(n): sqrt = int(math.sqrt(n)) + 1 for i in range(2, sqrt): if n % i == 0: return False return True def printPrime(a): primeResult = 0 nonPrimeResult = 0 for i in range(len(a)): if isPrime(a[i]): primeResult += a[i] else: nonPrimeResult += a[i] print('소수의 합 : ', primeR.. 2019. 5. 11.