[Spring] SpringBoot + MyBatis 설정

박이레·2023년 8월 3일
0

Spring

목록 보기
12/12

application.properties

mybatis.mapper-locations=classpath:mappers/**/*.xml

application.yml

mybatis:
  mapper-locations: classpath:mappers/**/*.xml

xml

<?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="">
  
</mapper>

테스트 코드

package com.example.demo;

import com.example.demo.domain.TempVO;
import com.example.demo.mapper.TempMapper;
import org.junit.jupiter.api.Test;
import org.mybatis.spring.boot.test.autoconfigure.MybatisTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;

@AutoConfigureTestDatabase(replace= AutoConfigureTestDatabase.Replace.NONE)
@MybatisTest
public class MyBatisTests {

    @Autowired(required = false)
    private TempMapper mapper;

    @Test
    public void create() {
        TempVO tempVO = TempVO.builder()
                .title("test")
                .content("test")
                .build();

        mapper.create(tempVO);
    }
}

@AutoConfigureTestDatabase(replace= AutoConfigureTestDatabase.Replace.NONE) 어노테이션이 중요!

profile
혜화동 사는 Architect

0개의 댓글