분류 전체보기
-
@Transactional이란 무엇인가Java 2023. 11. 22. 23:58
개요 친구가 문제를 줬다. dao.saveMail(mailDto); 이후에 예외가 발생하면 어떻게 될까? - 첨부파일은 이미 저장되어 있는데 삭제되어야 할까? - DB에 보낸 메일정보를 저장은 삭제되어야 할까? 검색해봤을 땐 스프링은 DB별로 에러코드를 정리해놔서 DB에서 생기는 에러코드를 통해 동적으로 예외를 전환해줄 수 있다는 것이다. 그래서 스프링이 제공하는 에러코드를 통해 동적으로 처리한다고 대답했지만, @Transactional 어노테이션에 대해서 찾아보면 좋을 것 같다고 추천해줘서 정리를 하려한다 트랜잭션이란? 트랜잭션이란 데이터베이스 관리 시스템 또는 유사한 시스템에서 상호작용의 단위이다. 여기서 유사한 시스템이란 트랜잭션이 성공과 실패가 분명하고 상호 독립적이며, 일관되고 믿을 수 있는 시..
-
생성자 주입(Constructor Injection)을 권장하는 이유Java 2023. 11. 20. 22:52
개요 스프링에서 의존성 주입(DI : Dependency Injection)하는 방법에는 크게 3가지가 있다. 생성자 주입(Constructor Injection), 필드 주입(Field Injection), 수정자 주입(Setter Injection)으로 각각의 차이점과 왜 생성자 주입을 사용해야하는지 정리해보고자 한다. 의존성 주입 : 필요한 객체를 직접 생성한는 것이 아닌 외부로부터 객체를 받아서 사용하는 것으로 코드의 결합도를 낮추고 재사용성을 증가시킨다. 생성자 주입(Constructor Injection) @Controller Public class TestController() { TestService testService; @Autowired //단일 생성자이기 때문에 @Autowired ..
-
[리팩토링] 가독성을 위한 리팩토링프로젝트/웹 ERD 프로젝트 2023. 11. 19. 22:57
피드백 내용 MemberDTO login = session.getAtrribute("login"); //현재 사용자 정보 이전까지 사용자 정보를 가져올때 이 문장을 계속 반복해서 썼었다. 나는 내가 쓴 코드라서 읽는데 불편함을 못느끼고 있었는데, 피드백을 받고보니 남이 봤을 땐 가독성이 떨어질 수 있겠다는 생각을 했다. 그리고 사용자 정보를 가져오는 반복되는 코드를 따로 private메서드로 만들어서 이름을 재정의하면 가독성을 높일 수 있다는 것은 생각도 못했었는데, 정말 좋은 방법인거 같다. private MemberDTO getUserInfoBySession() { MemberDTO login = session.getAtrribute("login"); //현재 사용자 정보 } @RequestMappi..
-
Early ReturnJava 2023. 11. 18. 23:48
개요 친구에게 프로젝트 피드백을 받던 중 라는 피드백을 받게되었다. 해당 기능은 메일을 전송하는 API였는데, 받는 사람이 아무도 없는 경우, 내게 메일 쓰기로 판단하고 내게 메일 쓰기 처리가 되도록 하는 기능이었다. 여러 if문이 중첩되고 부분이 있고, else if문까지 있었기 때문에 가독성이 떨어졌었다.그래서 early return을 정리해보려고 한다! Early Return은 무엇인가? Early Return은 메서드를 만드는 방법 중 하나로 특정 조건이 충족되면 함수나 메서드가 끝나기 전에 일찍 반환되는 것을 말한다. 즉, 함수가 메서드가 실행 중에 조건을 확인하고, 조건이 충족되면 나머지 코드를 실행하지 않고 즉시 반환한다. 프로젝트 코드에 적용하기 Early Return으로 수정 전 //메일..
-
JVMJava 2023. 11. 16. 21:02
JVM이란 자바 가상 머신인 Java Virtual Machine의 약자를 말한다. 가상 머신: 소프트웨어를 통해 구현된 컴퓨터 환경으로 실제 하드웨어와는 독립적으로 동작한다. 자바파일은 기본적으로 Java Compiler를 통해 바이트코드라는 형태의 중간 언어로 컴파일이 된다. 이 바이트코드는 JVM에서 실행이 되는데, JVM은 이 바이트코드를 해당 플랫폼의 기계어로 변환하고 실행한다. 이런 특성으로 자바 프로그램은 운영체제나 하드웨어에 의존하지 않고 여러 플랫폼에서 실행될 수 있으며, 특히 JVM은 자바의 핵심원칙 중 하나인 "Write once, Run Anywhere"의 핵심 역할을 수행한다. JVM구조 JVM은 크게 Class Loader, Execution Engine, Runtime Data..
-
Oracle 정규식알고리즘, SQL/SQL 2023. 11. 14. 12:02
개요 HackerRank에서 Weather Obervation Station12 문제를 풀고 있었다. 대충 해석해보니까 모음(a,e,i,o,u)로 시작하지도 끝나지도 않는 City들을 뽑으라는 것 같다.(중복되지 않도록) 그래서 SELECT DISTINCT city FROM station WHERE (city NOT LIKE 'A%' AND city NOT LIKE 'E%' AND city NOT LIKE 'I%' AND city NOT LIKE 'O%' AND city NOT LIKE 'U%') AND (city NOT LIKE '%a' AND city NOT LIKE '%e' AND city NOT LIKE '%i' AND city NOT LIKE '%o' AND city NOT LIKE '%u');..
-
Token인증 방식(JWT)과 Session인증 방식Java 2023. 11. 13. 23:58
개요 이제까지 배웠던 로그인 방식은 세션에 저장하는 방식만 배웠기에 다른 인증 방법이 있는줄 몰랐는데, 세션 방식말고도 토큰 방식 인증인 JWT가 있다는 것을 알게 돼서 정리해보고자 한다. HTTP의 특성 우선 로그인 인증방식으로 JWT와 Session을 알아보기 앞서서 왜 사용하는가를 알아볼 필요가 있다. HTTP는 비연결성(Connectionless)와 무상태성(Stateless)라는 특성을 가진다. 비연결성(Connectionless) HTTP는 연결을 유지하지 않는다. 라는 특성이 있다. 즉, HTTP는 서버와 클라이언트간 통신이 한 번 이뤄지고 나면 연결이 끊어진다는 것이다. 무상태성(Stateless) HTTP는 상태를 유지하지 않는다. 라는 특성이 있다. 즉, HTTP는 첫번째 통신 이후 두..
-
HackerRank) Weather Observation Station 4알고리즘, SQL/SQL 2023. 11. 12. 22:15
개요 SQL을 계속 안쓰다보니 까먹어서 다시 써보고자 HackRank문제를 풀어보기로 했다. 뭔말이지..? 하다가 아래 예시보고 이해했다. 전체 CITY리스트 중에서 유니크한 CITY리스트 개수를 빼라 오랜만에 쓰는 SQL이라 고유한 이름의 CITY 갯수를 어떻게 구하지? 하면서 //잘못된 예시임.. (SELECT COUNT(*) FROM station GROUP BY(city)) - (SELECT city, COUNT(*) FROM station GROUP BY city HAVING COUNT(*) = 1); 이런식으로 말도 안되게 헤매다가 검색하면서 알게 됐다. COUNT(DISTINCT 컬럼명)이 된다는 것을.. SELECT COUNT(city) - COUNT(DISTINCT city) FROM s..