본문 바로가기

개발

(82)
[Spring Boot] JPA + PostgreSQL 연결 개인프로젝트를 진행하면서 기존에 Oracle 또는 MySQL/MariaDB 반 사용하다가 이번에 PostgreSQL 를 사용해보고자 SpringBoot Data JPA + PostgreSQL 를 포스팅하겠습니다. PostgreSQL 은 AWS 에서 프리티어로 생성 1. build.gradle SpringData JPA , PostgreSQL Dependency 추가 dependencies { implementation 'org.springframework.boot:spring-boot-starter' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.postgresql:postgresql:42..
[JAVA] LocalDate 사용하여 현재 년,월,일 불러오기 및 포맷팅 Java8 버전부터 추가된 Local Date를 이용하면 쉽게 현재 년,월,일을 불러올 수 있다. import java.time.LocalDate; public class DateUtil { /** * 현재 날짜 불러오기 * @return */ public static LocalDate getCurrentDate() { return LocalDate.now(); } /** * 현재 날짜 불러오기 * @param pattern * @return */ public static String getCurrentDate(String pattern) { return LocalDate.now().format(DateTimeFormatter.ofPattern(pattern)); } /** * 현재 년도 불러오기 * @..
[SpringBoot3 + Log4j2] Routing 활용하여 요청별 로그파일 생성 1. gradle 설정 spring-boot-stater-logging exclude 처리 spring-boot-stater-log4j2 추가 plugins { id 'java' id 'org.springframework.boot' version '3.1.2' id 'io.spring.dependency-management' version '1.1.2' } group = 'com.example' version = '0.0.1-SNAPSHOT' java { sourceCompatibility = '17' } configurations { compileOnly { extendsFrom annotationProcessor } all { exclude group: 'org.springframework.boot'..
[React + TS] 부모컴포넌트 setState 함수 자식컴포넌트로 Props 전달 React + TypeScript 에서 부모컴포넌트 에서 자식 컴포넌트로 setState 함수를 넘길때 자식 컴포넌트에서 타입정의를 하지 않으면 에러가발생한다. 아래와 같이 자식 컴포넌트에서 interface 를 사용하여 타입을 정의하여 사용한다. 부모컴포넌트 () const Parent = () => { const [value, setValue] = useState(""); return ( ) } 자식컴포넌트() interface ParentProps { setValue: React.Dispatch } const Children = ({setValue}: ParentProps) => { useEffect( () => { setValue("...") }) return ( ... ) }
[Spring Boot] JPA, AuditorAware 사용하여 사용자정보 자동 입력 1. Config 생성 @EnableJpaAuditing 어노테이션을 추가하여 Annotation 을 사용하여 Audit 활성화 @Configuration @EnableJpaAuditing public class JpaAuditConfig { @Bean public AuditorAware auditorProvider() { return new AuditorAwareImpl(); } } 2. AuditorAware 구현체 생성 getCurrentAuditor() 를 구현하여 등록자, 수정자에 사용될 사용자 정보를 불러온 후 리턴한다. public class AuditorAwareImpl implements AuditorAware { @Override public Optional getCurrentAudit..
[Spring Boot] AutoConfigureMockMvc 사용하여 Controller 테스트 1. Sample Controller 생성 @RestController @Slf4j @RequestMapping("/sample-board") public class SampleBoardController { private SampleBoardService sampleBoardService; public SampleBoardController(SampleBoardService sampleBoardService) { this.sampleBoardService = sampleBoardService; } @GetMapping public List getSampleBoards() { ///sample-board return sampleBoardService.getSampleBoards(); } } 2. Test..
[Spring Boot] H2 + JPA 세팅 1. Gradle Dependencies 추가 implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'com.h2database:h2:2.1.214' * dependency 추가시 로컬 PC에 설치된 h2 버전과 동일하게 맞추는것이 좋다. 2. application.properteis 추가 #setting h2 spring.h2.console.enabled=true spring.h2.console.path=/h2-console #setting h2 db spring.datasource.url=jdbc:h2:tcp://localhost/~/test spring.datasource.driver-class-na..
[Spring] 메이븐(maven) 멀티모듈(multi-module) 활용 최근 프로젝트에서 사용자용 모바일 웹앱 , 그리고 어드민용 웹 개발을 진행하게 되었다. 최종적으로 두개의 war 파일을 배포해야 하기 때문에 멀티 모듈을 사용하기로 하였다. 이번에 진행한 멀티 모듈 구조는 간략하게 아래와 같다. 사용자용 어플리케이션, 관리자용 애플리케이션인 각 서비스의 시작점인 controller를 생성한다. 각 어플리케이션 컨트롤러에서는 공통 소스(core)에 있는 서비스를 호출한다 그럼 위 기준으로 프로젝트를 생성하고 모듈을 추가해보도록 하겠다. IDE는 IntelliJ를 사용하였다. 1. TOP 프로젝트 생성 File -> New -> New Project 선택 Maven 선택후 Next 프로젝트명 입력후 Finish 아래와 같이 프로젝트가 생성된 것을 확인한다. 2. Module..