본문 바로가기

분류 전체보기

(287)
MyBatis | ResultMap ResultMap을 사용하면 복잡한 결과를 객체에 간단히 매핑할 수 있다. 사용 방법은 간단하다. User라는 객체가 있을 때 아래와 같이 을 작성하면 된다. public class User { private String name; private int age; } SELECT user_name, user_age FROM USERS 만약 클래스간 포함관계, 즉 멤버변수로 다른 객체를 가지고 있다면 을 이용해 매핑해 줄 수 있다. 조인을 하거나 보다 복잡한 매핑에서 훨씬 유용하다. public class Address { private String zipcode; private String address; } public class User { private String name; private int a..
React | 브라우저 뒤로가기 버튼 감지 react-router-dom으로 브라우저의 뒤로가기 버튼 클릭을 감지할 수 있다. history.listen을 이용하는 방법인데, location이 변경될 때 마다 실행되는 콜백 함수다. const history = useHistory(); useEffect(() => { let unlisten = history.listen((location) => { if (history.action === 'PUSH') { } if (history.action === 'POP') { } }); return () => { unlisten(); }; }, [history]); GitHub - remix-run/history: Manage session history with JavaScript Manage sessio..
Spring Boot | Spring Security JWT 인증 처리 과정 JWT 인증 과정 정리하기 위해 작성해 본다. JWT 생성 과정은 생략한다. dependency 스프링 시큐리티와 JWT를 사용하기 위한 라이브러리를 추가한다. dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'com.auth0:java-jwt:3.18.1' } 시큐리티 설정을 해준다. 일단 configure()는 기본만.. @EnableWebSecurity로 시큐리티 사용을 설정하면, 자동으로 스프링 시큐리티에서 ..
Spring Boot | Request 마다 로그 찍기 HandlerInterceptor HandlerInterceptor 인터페이스를 구현하는 방법. preHandle()의 반환 값을 true로 설정한다. @Slf4j @Component public class CustomRequestInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { HttpServletRequest requestCacheWrapperObject = new ContentCachingRequestWrapper(request); request..
CentOS 7 nginx install, ReactJS 배포 yum에 nginx를 위한 외부 리포지토리를 추가한다. /etc/yum.repos.d폴더 내에 nginx.repo파일을 생성한다. $ touch nginx.repo $ vi nginx.repo그 후 아래 내용 붙여넣기 [nginx] name=nginx repo baseurl=https://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1 centOS의 버전이 5혹은 6이라면 $releassever에 직접 버전을 입력한다. 외부 리포지토리를 연결한 후, yum을 이용해 설치한다. $ sudo yum install nginx conf파일을 작성해야 하는데, 리액트를 기준으로 작성했다. /etc/nginx/conf.d폴더 아래에 새로운..
Spring Boot | war 빌드, 외부 톰캣 사용 (WAS에 배포하기) Spring Boot는 내부 톰캣이 있고.. jar로 빌드한다.. 하지만... JSP를 써야했고.. war로 외부 톰캣에 배포해야 할 일이 생겼다... war로 빌드 일단 war로 빌드하는 설정은 아주 간단하다.. id 'war'를 추가해주면 와르로 와르르 plugins { id 'org.springframework.boot' version '2.5.5' id 'io.spring.dependency-management' version '1.0.11.RELEASE' id 'java' id 'war' } 근데 이렇게만 하고 자연스럽게 배포했고, 로그에 started.. 잘 됐다고 떴는데 404에러가 떴다.. ..
Spring | JDBCTemplate 사용하기 JPA와 QueryDsl 사용 중.. FROM절 서브쿼리 조인이 필요해서 부득이하게 JdbcTemplate을 함께 사용하게 됐다. 오랜만에 사용하니까 어려워서 정리해본다.. RowMapper RowMapper 인터페이스를 구현하면 쿼리 실행 결과를 바로 POJO 객체에 매핑시킬 수 있다. @AllArgsConstructor @Getter public class AnimalResponseDto { private String name; private String breed; private int age; } 매핑시킬 코드를 작성한 후 사용하면 끝!! public class AnimalRowMapper implements RowMapper { @Override public AnimalResponseDto ma..
React | 파일 다운로드 참고 https://gist.github.com/javilobo8/097c30a233786be52070986d8cdb1743 Spring Boot로 만든 API에서 엑셀 파일을 다운로드 해보자.. axios {responseType: 'blob'}설정을 해준다. 이러함.. apiClient는 axios.create()으로 만든 모듈?이다. const res = await apiClient.get(url, { responseType: 'blob', }); return res;download useAsync를 사용해서 state값이 성공이면.. data 상태값이 변경되게 된다. 그래서 useEffect()로 처리했다. 혹시몰라 컴포넌트가 언마운트되면 해당 링크도 삭제하게 만들었다..