vue-router로 컴포넌트 이동시 이전 컴포넌트 상태 유지

방법 <KeepAlive> 컴포넌트를 사용하면, 이전 컴포넌트의 상태를 캐싱했다가 뒤로돌아가도 유지된다. https://vuejs.org/guide/built-ins/keep-alive.html#basic-usage KeepAlive의 상태 유지 방법 KeepAlive 컴포넌트 레벨에서 캐싱이 이루어지고 있다. 만약 중간에 KeepAlive DOM이 사라지면 캐싱이 지워진다. https://github.com/vuejs/vue/blob/dev/src/core/components/keep-alive.js#L90 참고 자료 https://stackoverflow.com/questions/41764825/preserve-component-state-with-vue-router https://stackoverflow.com/questions/71145498/where-does-vuejs-store-the-cached-component-when-using-keep-alive

2024-09-15 · 1 min · 33 words

vue-router 파라미터 가져오기

방법 $route.params를 통해 가져올 수 있다. pattern matched path $route.params /users/:username /users/eduardo { username: ’eduardo’ } /users/:username/posts/:postId /users/eduardo/posts/123 { username: ’eduardo’, postId: ‘123’ } 참고 자료 https://router.vuejs.org/guide/essentials/dynamic-matching.html

2024-09-15 · 1 min · 27 words

VSCode에서 SSH 연결하기

VSCode로 SSH 환경에서 작업을 해야되는 상황이었다. 1. Remote Development 설치 VSCode에서 확장 프로그램을 설치 해야된다. 아래 경로에서 설치 가능하다. https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack 2. Config 파일 수정 config 파일을 수정해서 자신이 접속할 경로와 사용자명을 작성하면 된다. Windows 기준 아래의 경로에 파일이 존재한다. C:\Users\사용자명\.ssh\config 해당 파일의 다음과 같은 파일 형식으로 지정해두면 이후에 쉽게 접속이 가능해진다. 아래 예시는 pem 키를 이용해서 접속하는 경우다. pem키를 사용하지 않고 사용지 비밀번호를 입력하는 경우는 4번 라인의 IdentityFile 을 제거하면된다....

2024-09-15 · 1 min · 75 words

verify

목표 mockito의 verify() 메서드를 통해 검증할 수 있는 내용들을 알아본다. 호출된 횟수 검증 List<String> mockedList = mock(MyList.class); mockedList.size(); verify(mockedList, times(1)).size(); 호출되지 않음을 검증 List<String> mockedList = mock(MyList.class); mockedList.size(); verify(mockedList, never()).clear(); 호출되는 인자 매칭 커스터마이징 인자 매칭 기준이 복잡하다면 ArgumentMatchers.argThat() 을 통해서 매칭 기준을 커스터마이징할 수 있다. 인자로 ArgumentMatcher라는 함수형 인터페이스를 받고 있어서 람다로 구체적인 조건을 명시할 수 있다. 참고 자료 https://www.baeldung.com/mockito-verify https://www.baeldung.com/mockito-argument-matchers

2024-09-15 · 1 min · 62 words

UsingRecursiveFieldByFieldElementComparator 사용시 일부 필드는 제외하는 방법

assertThat(actual) .usingRecursiveFieldByFieldElementComparator() .usingElementComparatorIgnoringFields("field_1", "field_2") .isEqualTo(expected) 참고 자료 https://issueexplorer.com/issue/assertj/assertj-core/2263

2024-09-15 · 1 min · 8 words

useEffect 사용법

목표 useEffect 사용법을 이해한다. useEffect Effect는 특정 이벤트가 아닌 렌더링에 의해 발생한 사이드 이펙트를 명시할 수 있다. 채팅에서 메시지를 보내는 것은 사용자가 특정 버튼을 클릭함으로써 직접 발생하므로 이벤트다. 서버 연결은 컴포넌트가 표시되는 유저와의 상호작용과 관계 없이 발생해야 되므로 이펙트다. Effect는 외부 시스템과 동기화할 때 사용하면 좋다. 렌터링 될 때마다 실행하기 function MyComponent() { useEffect(() => { // Code here will run after *every* render }); return <div />; } Effect의 의존성 명시하기 모든 렌더링에 대해서 실행되지 않아야되는 경우가 있다....

2024-09-15 · 1 min · 196 words

URL에 파라미터 사용하기

url에 유동적으로 바뀌는 부분이 있다면 파라미터를 사용하여 처리할 수 있다. RestAssured.given() .when() .get("http://restcountries.eu/rest/v1/name/{country}", cty) .then() .body("capital", containsString("Helsinki")); 참고 자료 https://stackoverflow.com/questions/32475850/how-to-pass-parameters-to-rest-assured

2024-09-15 · 1 min · 20 words

Url Encoding, Decoding 하기

URLEncoder.encode(value, StandardCharsets.UTF_8.toString()); URLDecoder.decode(value, StandardCharsets.UTF_8.toString()); https://www.baeldung.com/java-url-encoding-decoding

2024-09-15 · 1 min · 5 words

UnaryOperator T 함수형 인터페이스

T를 인자로 받고 T를 반환한다.

2024-09-15 · 1 min · 5 words

Type을 만족하는 모든 Bean 주입하기

생성자나 setter에 List 를 파라미터로 두면 된다. public Class Xyz { private List<Daemon> daemons; @Autowired public void setDaemons(List<Daemon> daemons){ this.daemons = daemons; } }

2024-09-15 · 1 min · 24 words

TreeSet

지속적으로 정렬 상태를 유지하면서, 새로운 데이터가 추가/삭제가 자주 일어나는 경우가 있었다. 쉽게 말해서 균형 잡힌 이진 트리인 레드 블랙 트리를 사용해야 됐다. TreeSet은 Set 인터페이스의 구현체다. 대표 메서드 TreeSet에서 사용되는 대표적인 메서드를 정리해본다. E floor(E e): e 이하인 객체 중 가장 큰 값을 리턴한다. 없으면 null이 리턴된다. O(log n) E ceiling(E e): e 이상인 객체 중 가장 작은 값을 리턴한다. 없으면 null이 리턴된다. O(log n) E higher(E e): e 초과인 객체 중 가장 작은 값을 리턴한다....

2024-09-15 · 1 min · 126 words

transient란

Serializable 을 구현한 클래스에서 필드 중에 직렬화를 원치 않는 필드에 붙이면 된다. public class DispatcherServlet extends HttpServlet { private static final long serialVersionUID = 1L; private static final Logger log = LoggerFactory.getLogger(DispatcherServlet.class); private static final HandlerAdapter HANDLER_ADAPTER = new DefaultHandlerAdapter(); private final transient HandlerMappings handlerMappings; public DispatcherServlet() { this.handlerMappings = new HandlerMappings(); } //... } https://nesoy.github.io/articles/2018-06/Java-transient

2024-09-15 · 1 min · 56 words

TransactionTemplate 이용한 트랜잭션 관리

@Transactional 어노테이션을 사용하지 않고, 트랜잭션을 직접 관리하고 싶은 경우가 있었다. 이때 TransactionTemplate를 사용하면 된다. 트랜잭션 외부에 리턴을 해야되는 경우 return transactionTemplate.execute(new TransactionCallback() { // the code in this method runs in a transactional context public Object doInTransaction(TransactionStatus status) { updateOperation1(); return resultOfUpdateOperation2(); } }); 트랜잭션 외부에 리턴이 필요없을 경우 transactionTemplate.execute(new TransactionCallbackWithoutResult() { protected void doInTransactionWithoutResult(TransactionStatus status) { updateOperation1(); updateOperation2(); } }); 참고 자료 https://docs.spring.io/spring-framework/docs/current/reference/html/data-access.html#tx-prog-template

2024-09-15 · 1 min · 64 words

toString() 메서드가 나올 경우

assertThat(obejct.toString()).isEqualTo("\"value\""); 위의 코드는 아래의 방식으로 바꿀 수 있다. assertThat(obejct).hasToString(expectedString)

2024-09-15 · 1 min · 9 words

TLS vs SSL

SSL(Secure Sockets Layer)은 보안 소켓 계층 이라는 뜻으로 인터넷을 통해 전달되는 정보 보안의 안전한 거래를 허용하기 위해 Netscape 사에서 개발한 인터넷 통신 규약 프로토콜이며, TLS(Transport Layer Security)는 SSL 3.0을 기초로 해서 IETF가 만든 프로토콜로 이는 SSL3.0을 보다 안전하게 하고 프로토콜의 스펙을 더 정확하고 안정성을 높이는 목적으로 고안되었다. 추후에 추가적인 학습이 필요하다. 참고 자료 https://waspro.tistory.com/161

2024-09-15 · 1 min · 54 words

TIMESTAMP vs DATETIME

목표 TIMESTAMP와 DATETIME의 차이점을 이해한다. 크기 5.6.4 버전 이후 기준 TIMESTAMP는 기본적으로 4 bytes에 소수점 표현을 위해 0~3 bytes를 추가로 사용한다. DATETIME은 기본적으로 5 bytes에 소수점 표현을 위해 0~3 bytes를 추가로 사용한다. 표현 범위 TIMESTAMP: 1970-01-01 00:00:00 ~ 2038-01-19 03:14:17 DATETIME: 1000-01-01 00:00:00 ~ 9999-12-31 23:59:59 따라서, 2038년이 넘는 날짜가 필요하면 TIMESTAMP를 사용할 수 없다. Timezone DATETIME은 timezone에 대해서 아무것도 처리되지 않는다. TIMESTAMP는 timezone에 대한 처리가 이루어진다. 저장 시 TIMESTAMP 값을 현재 timezone 에서 UTC로 변환 조회 시 UTC에서 현재 timezone으로 변환 예시 CREATE TABLE timezone_test ( `timestamp` TIMESTAMP, `datetime` DATETIME ); SET SESSION time_zone = '+00:00'; INSERT INTO timezone_test VALUES ('2029-02-14 08:47', '2029-02-14 08:47'); SELECT * FROM timezone_test; -- | timestamp | datetime | -- |---------------------|---------------------| -- | 2029-02-14 08:47:00 | 2029-02-14 08:47:00 | SET SESSION time_zone = '-05:00'; SELECT * FROM timezone_test; -- | timestamp | datetime | -- |---------------------|---------------------| -- | 2029-02-14 03:47:00 | 2029-02-14 08:47:00 | 참고 자료 https://planetscale....

2024-09-15 · 1 min · 155 words

TIMESTAMP ms 단위까지 저장하기

TIMESTAMP(3) 이라고 타입을 지정하면 ms단위까지 저장한다. 참고 자료 https://mariadb.com/kb/en/timestamp/ https://stackoverflow.com/questions/26299149/timestamp-with-a-millisecond-precision-how-to-save-them-in-mysql/26299379

2024-09-15 · 1 min · 10 words

ThreadLocal

배경 ThreadLocal 의 용도와 동작 방식을 알아본다. ThreadLocal이란? 하나의 스레드에서 고유하고 독립적인 변수를 갖게 해주는 클래스다. 스레드가 사라진 뒤에 해당 변수는 GC 대상이 된다. get(), set(), remove() 메서드만 존재하는 단순한 구조다. 예를 들어 스레드 마다 고유한 id를 생성하기 위해서 아래와 같이 사용할 수 있다. public class ThreadId { // Atomic integer containing the next thread ID to be assigned private static final AtomicInteger nextId = new AtomicInteger(0); // Thread local variable containing each thread's ID private static final ThreadLocal<Integer> threadId = new ThreadLocal<Integer>() { @Override protected Integer initialValue() { return nextId....

2024-09-15 · 1 min · 116 words

Thread pool 생성

배경 Executors.newFixedThreadPool(10)의 의미를 알아본다. Executors.newFixedThreadPool() 고정된 개수의 스레드를 가지는 스레드풀을 생성한다. 반환 값은 ExecutorService이다. ExecutorService executor = Executors.newFixedThreadPool(10); ExecutorService ExecutorService는 인터페이스이며, execute() 메서드를 통해 파라미터로 Callable이나 Runnable을 넘겨주면 스레드풀에서 해당 작업을 할당해 실행해준다. executorService.execute(runnableTask); ExecutorService는 수동으로 소멸시켜줘야된다. shutdown() 메소드는 즉시 소멸되지 않고, 현재 실행 중인 스레드가 모드 완료되고 소멸된다. shutdownNow(): 현재 실행중인 스레드들을 즉시 멈추고 소멸시킨다. 또한, 실행 중이던 작업들을 반환한다. executorService.shutdown(); List<Runnable> notExecutedTasks = executorService.shutDownNow(); 참고 자료 https://www.baeldung.com/java-executor-service-tutorial

2024-09-15 · 1 min · 69 words

thenAnswer vs thenReturn

목표 thenAnswer와 thenReturn의 차이를 알아본다. 차이점 thenReturn은 정적인 반환 값을 설정할 때 사용한다. thenAnswer은 호출에 대한 추가적은 작업이 필요하거나, 동적인 반환 값이 필요할 때 사용한다. thenAnswer thenAnswer는 Answer 타입의 인자를 갖는다. Answer는 함수형 인터페이스이다. 아래 사진처럼 Answer의 메서드의 인자인 InvocationOnMock은 호출한 메소드의 인자를 반환하거나, 해당 메소드를 반환, mocking한 대상 객체를 반환도 할 수 있어서 유연하게 사용할 수 있다. 참고 자료 https://stacktraceguru.com/unittest/thenreturn-vs-thenanswer https://www.baeldung.com/mockito-additionalanswers https://javadoc.io/static/org.mockito/mockito-core/3.1.0/org/mockito/invocation/InvocationOnMock.html

2024-09-15 · 1 min · 63 words