Newer
Older
task-bldg / src / main / java / osm / surveyor / task / city / DataLoader.java
@haya4 haya4 on 16 Jul 2022 1 KB CityIndex
  1. package osm.surveyor.task.city;
  2.  
  3. import java.io.InputStream;
  4.  
  5. import org.springframework.boot.CommandLineRunner;
  6. import org.springframework.core.io.ClassPathResource;
  7. import org.springframework.stereotype.Component;
  8.  
  9. import com.fasterxml.jackson.databind.ObjectMapper;
  10.  
  11. import lombok.RequiredArgsConstructor;
  12. import osm.surveyor.task.city.model.City;
  13. import osm.surveyor.task.city.model.CityIndex;
  14.  
  15. @RequiredArgsConstructor
  16. @Component
  17. public class DataLoader implements CommandLineRunner {
  18. private final CityRepository repository;
  19. @Override
  20. public void run(String... args) throws Exception {
  21. // 「src/main/resources/static/city/index.json」を読み込む
  22. try (InputStream is = new ClassPathResource("static/city/index.json").getInputStream()) {
  23. /*
  24. ObjectMapper mapper = new ObjectMapper();
  25. CityIndex index = mapper.readValue(is, CityIndex.class);
  26. for (City city : index.getList()) {
  27. repository.save(city);
  28. }
  29. */
  30. }
  31. }
  32.  
  33. }