※ XML을 사용하지 않고, mapper interface 를 생성하여서 쿼리문을 작성
참고 URL :
https://pooney.tistory.com/47
https://kouzie.github.io/spring/Spring-Boot-%EC%8A%A4%ED%94%84%EB%A7%81-%EB%B6%80%ED%8A%B8-Mybatis/##mybatis
https://passionha.tistory.com/45
https://dongdd.tistory.com/178
https://jason-moon.tistory.com/130
dependencies {
//mybatis 사용을 위해 추가
compile 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.0'
compile 'org.springframework.boot:spring-boot-starter-jdbc'
compile 'mysql:mysql-connector-java'
}
=================================================================================================================
import org.apache.ibatis.annotations.*;
public interface CoinMapper {
}
=================================================================================================================
value 안에는 위에서 생성한 맵퍼 인터페이스의 경로를 설정
=================================================================================================================
@SpringBootApplication
@MapperScan(value={"com.sungchul.ifbuy.coin.mapper"})
public class IfbuyApplication {
}
=================================================================================================================
=================================================================================================================
public interface CoinMapper {
@Select("SELECT now()")
public String time();
@Insert("INSERT INTO coin_price (" +
"korean_name, " +
"english_name, " +
"market, " +
"opening_price, " +
"high_price, " +
"low_price, " +
"trade_price, " +
"candle_acc_trade_price, " +
"candle_acc_trade_volume, " +
"unit, " +
"candle_date_time_kst, " +
"candle_date_time_utc )" +
"VALUES(" +
"##{koreanName}, " +
"##{englishName}, " +
"##{market}, " +
"##{coinPriceVO.openingPrice}, " +
"##{coinPriceVO.highPrice}, " +
"##{coinPriceVO.lowPrice}, " +
"##{coinPriceVO.tradePrice}, " +
"##{coinPriceVO.candleAccTradePrice}, " +
"##{coinPriceVO.candleAccTradeVolume}, " +
"##{coinPriceVO.unit}, " +
"##{coinPriceVO.candleDateTimeKst}, " +
"##{coinPriceVO.candleDateTimeUtc}) ")
public void insertCoinPrice(CoinVO coinVO);
}
=================================================================================================================
맵퍼인터페이스를 선언하여 사용,
@Autowired 를 사용해서 주입해도 됨
=================================================================================================================
public class CoinService {
CoinMapper coinMapper;
=================================================================================================================
https://smujihoon.tistory.com/222
yml 파일 밑에 하단의 내용 추가
=================================================================================================================
mybatis:
configuration:
map-underscore-to-camel-case: true
=================================================================================================================