본문 바로가기

Programming Practice/Spring

query XML 에서 사용하는 Vo(Entity) type 의 alias 지정 1. 배경query XML 에서 parameterType 이나 resultMap 에서 Vo(Entity) 의 type(경로.class명)이 필요할 때가 있다. (parameter 나 result 가 Vo(Entity)에 담겨져 있을 때)이때 type(경로.class명)을 type 이 필요할 때마다 적어주는 것은 불필요한 반복이다. 따라서 type 에 alias를 주고, alias를 type 에 적어주면, 불필요한 반복을 피할 수 있다. 2. 사용1) mybatis-config.xml 2) DispatcherServlet-context.xml 3) queryXml 에서 type 에 경로.class명 대신 alias를 사용 더보기
Spring transaction 설정_MySQL 1. 배경1) 특별한 설정이 없을 경우, SqlSession은 개별 쿼리 별로 commit, rollback을 수행한다.2) method 에서 insert, update, delete 쿼리를 수행해서 method 별로 commit, rollback을 수행할 경우 아래와 같이 한다.Spring 에서는 개별 코드별로 transaction을 설정하지 않고, (programming transaction - 세세한 것의 설정이 가능하나, 코드 반복이 있고, 실수하기 쉽다.) transaction을 사용하겠다는 선언을 통해(declarative transaction) transaction을 설정할 수 있다.2. 사용1) DispatcherServlet-context.xmltransactionManager에 대해 아.. 더보기
Repository(Dao) 에서 SqlSession 사용_MySQL 1. SqlSession 이란?쿼리 실행, commit, rollback에 사용되는 객체 2. Repository(Dao) 에서 SqlSession 사용하는 방법1) DispatcherServlet-context.xmldataSource, sqlSessionFactory, userMapper 에 대해 아래와 같이 설정한다. 2) java(Repository): class 선언 시 extends SqlSessionDaoSupport 를 한다.: sqlSession을 가져와서 query를 호출한다. public class InMemoryProductRepository extends SqlSessionDaoSupport implements ProductRepository{ public List getAllPr.. 더보기
MyBatis를 통한 Spring과 MySQL 연결 자세한 사항은 아래 URL 참고https://mybatis.github.io/spring/index.html 1. MySQL 과 MyBatis 관련 library 설치 - pom.xml 에서 아래 dependency 추가 org.mybatis mybatis 3.1.1 org.mybatis mybatis-spring 1.1.1 mysql mysql-connector-java 5.1.21 2. DispatcherServlet-context.xml 설정 (datasource, sqlSessionFactory) 3. 쿼리 결과를 담을 entity class 생성 4. 쿼리를 목록으로 하는 interface 생성 - src/main/java 에 위치 - @Select 와 같은 쿼리 annotation은 매핑되는 .. 더보기
Dispatcher Servlet 설명 1. Dispatcher Servlet 이란? - dispatch : 보내다 - dispatch request to the correct controller's method 2. DispatcherServlet-servlet.xml - Dispatcher Servlet 이 동작할 때 필요한 설정 정보를 정의 - WEB-INF 아래 위치 - 기본적인 설정 정보 RequestMapping annotation을 사용하겠다 matrix-variables를 활용하겠다. webapp/resources 아래 파일들을 view 에서 static 요소로 활용하겠다. controller를 호출하기 전, view를 return하기 전에 특정 로직을 수행하는 interceptor를 사용하겠다. 예를 들어 controller .. 더보기
기본적인 pom.xml 설정 1) pom - Projet Object Model2) pom.xml - Configuration file that defines required dependencies (specified jars - library)3) 작동 원리 - build 시, pom.xml 을 읽어서, dependency에 정의된 jar 파일을 Maven Central Binary Repository 에서 download 한다. - addressing system 이 있으며, Group Id, Artifact Id, version 정보로 구별한다. - scope 에서는 일반적으로 compile을 선택하나, provided를 선택하는 경우도 있다. * compile : complie 시 provided 되고, war package.. 더보기