Spring
MyBatis (ORM object relational mapping)
의존성 설정 → DB 설정 → MyBatis 설정 > Mapper interface 작성 > XML작성
장점
예시
<select id="getUserList" resultType="User"> SELECT * FROM users <where> <if test="name != null"> // 동적 쿼리 AND name = #{name} </if> <if test="email != null"> // 동적 쿼리 AND email = #{email} </if> </where></select>
MyBatis 사용설정
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/> // mysql 드라이버
<property name="url" value="jdbc:mysql://localhost:3306/mydatabase"/> // mysql 사용
<property name="username" value="username"/> // 아이디
<property name="password" value="password"/> // 비밀번호
</bean>