Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- 고등학생 대상
- ICT멘토링
- suricata
- Python
- Resnet
- API
- Web
- 인터넷의이해
- Database
- rnn
- git
- Rocky Linux
- Machine Learning
- C언어
- 국가과제
- cloud
- Powershell
- colab
- Github
- Spring Boot
- OSS
- ChatGPT
- 크롤링 개발
- Spring
- LINUX MASTER
- GoogleDrive
- VSCode
- Docker
- KAKAO
- 코딩도장
Archives
- Today
- Total
코딩두의 포트폴리오
데이터 로더 본문
데이터 로더(Data Loader)란?
스프링 부트 시작 시 자동으로 실행
기본 데이터를 DB에 불러오는 데(삽입하는 데) 사용하는 클래스
보통 'commandLineRunner' 인터페이스를 구현
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import com.example.demo.entity.TouristSpot;
import com.example.demo.repository.TouristSpotRepository;
@Component
public class DataLoader implements CommandLineRunner {
@Autowired
private TouristSpotRepository touristSpotRepository;
@Override
public void run(String... args) throws Exception {
// 기본 데이터 추가
TouristSpot spot1 = new TouristSpot();
spot1.setName("Gyeongbokgung Palace");
spot1.setDescription("Historic palace in Seoul");
touristSpotRepository.save(spot1);
TouristSpot spot2 = new TouristSpot();
spot2.setName("Jeju Island");
spot2.setDescription("Beautiful island in South Korea");
touristSpotRepository.save(spot2);
}
}
'2024 Tourism Data Utilization Contest > Spring Boot' 카테고리의 다른 글
HTML 파일 생성 (1) | 2024.06.20 |
---|---|
Thymeleaf dependency 추가 (0) | 2024.06.20 |
설정 파일 (0) | 2024.06.20 |
컨트롤러 (0) | 2024.06.20 |
서비스 계층 설정 (0) | 2024.06.20 |