annotation 4

Spring(11) - Spring & Mybatis 실습2 : Transaction처리

0. Transaction처리 해주는 이유 transaction이란 DB의 작업 단위이다. Spring에서 SqlSession을 관리할 때, default가 AutoCommit으로 되어있다. Transaction관리자를 등록해서 DB에 작업을 했을 때, Exception이 없으면 commit하고, 있으면 알아서 rollback해주기 위해 사용된다. 1. Transaction library추가 pom.xml에 아래 코드를 추가해서 maven update를 해서 적용시킨다. org.springframework spring-tx ${org.springframework-version} 2. Transaction 관리할 객체 생성&등록하기 1. namespace에 tx 추가하기 root-context.xml의 N..

Programming/Spring 2022.05.07

Spring (4) - MySQL과 연결하기

0. DB 관련 library 불러오기 아래 사이트에서 코드를 복사해서 설정파일(application.xml 또는 pom.xml)에 붙여넣고 저장한다. 1) MySQL이 제공하는 connector https://mvnrepository.com/artifact/mysql/mysql-connector-java/8.0.28 2) jdbc https://mvnrepository.com/artifact/org.springframework/spring-jdbc/5.3.19 1. DB 테이블과 DTO(데이터 객체) 만들기 Workbench를 열어, 이름과 나이 정보를 담을 테이블을 만든다. DB에서 값을 읽어와서 출력하는 기능 구현이 목표라서 값을 미리 넣어준다. create database testdb; use t..

Programming/Spring 2022.04.25

Spring (3) - Container에 객체(Bean) 설정하기4 : Java

xml파일 없이, 완전한 Annotation은 Java를 통해 구현할 수 있다. 1. 등록할 객체에 Annotation 작성하기 아래 글에서 2. Annotation 작성하기 를 따라 작성하면 된다. 2022.04.23 - [웹프로그래밍/Spring] - Spring (3) - Container에 객체(Bean) 설정하기3 : Annotation Spring (3) - Container에 객체(Bean) 설정하기3 : Annotation 0. Annotation 1. Stereotype Annotation Stereotype Annotation은 Bean을 등록할 때 사용할 수 있는 annotation이다. Stereotype 적용 대상 @Controller MVC Controller에 사용 @Servi..

Programming/Spring 2022.04.23

Spring (3) - Container에 객체(Bean) 설정하기3 : Annotation

0. Annotation 1. Stereotype Annotation Stereotype Annotation은 Bean을 등록할 때 사용할 수 있는 annotation이다. Stereotype 적용 대상 @Controller MVC Controller에 사용 @Service Service 계층 @Repository DB에 접근하는 계층 ex) DAO @Component 위의 계층에 속하지 않은 경우 ex) DTO 등 2. 의존 관계 설정 Annotation Annotation 설명 @Autowired Spring에서만 사용 가능 멤버 변수, setter, constructor, 일반 method에 사용 가능하며 타입에 맞춰서 연결함 예시 => 2022.04.20 - [웹프로그래밍/Spring] - Spr..

Programming/Spring 2022.04.23