설정
1. 폼에 추가
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId> //mybatis 그 자체
<version>3.4.6</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId> //mybatis와 spring 연결 역할
<version>1.3.2</version>
</dependency>
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation"
value="classpath:/mybatis-config.xml"/>
</bean>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
최신 버전의 Spring에서는 <mappers> 생략 가능 (스프링 내에서 자동으로 잡아준다.)
<configuration>
<typeAliases>
<typeAlias alias="Address" type="park.md.domain.Address"/>
</typeAliases>
<mappers>
<mapper resource="park/md/mapper/AddressMapper.xml"/>
</mappers>
</configuration>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="park.md.mapper.AddressMapper">
[sql 지정]
</mapper>
5. root-context에 해당 내용 추가
<context:component-scan base-package="park.md.mapper"/>
<mybatis-spring:scan base-package="park.md.mapper"/>
글이 영.. 성의가 없네요 떼잉