개발 수업/Spring
[spring] TypeAliases/sqlSession
오늘 하루s
2023. 8. 9. 23:16
728x90
더보기
Day72. 230809
TypeAliases
mybatis에서 많이 쓰이는 것들을 typeAliases로 정해두어 Aliases를 사용해 간편하게 resultType을 써줄 수 있다.
그 중 자바의 데이터타입이 내장되어 별칭(alias)으로 제공되고 있다.
Alias(별칭) | Mapped Type(자바의 데이터타입) |
short | Short |
int | Integer |
string | String |
hashmap | Hashmap |
list | List |
arraylist | ArrayList |
길게 써야했던 resultType을 int로 간단하게 쓸 수 있다.
추가로 비교연산자(<,>)를 처리하거나 쿼리문을 구분지어주기 위해 <![CDATA[]]>안에 쿼리문을 써준다.
sqlSession
앞에서 action-mybatis.xml에서 sqlSession이름으로 등록해두었다.
<!-- sqlSession이름으로 bean등록 -->
<bean id="sqlSession"
class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory"></constructor-arg>
</bean>
그래서 sqlSession 객체를 만들지않고 @Autowired을 사용해 필드명만 선언해도 객체가 선언된다.
스프링프레임워크에서 자동으로 객체를 만들어 주기때문에 jsp프로젝트를 할 때 보다 훨씬 간편해졌다.
728x90