GenApplication.java 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package com.gitee.gen;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. import org.springframework.boot.web.servlet.ServletComponentScan;
  5. import org.springframework.core.io.ClassPathResource;
  6. import org.springframework.util.FileCopyUtils;
  7. import java.io.File;
  8. import java.io.FileOutputStream;
  9. import java.io.IOException;
  10. @ServletComponentScan
  11. @SpringBootApplication
  12. public class GenApplication {
  13. public static void main(String[] args) {
  14. initDatabase();
  15. SpringApplication.run(GenApplication.class, args);
  16. }
  17. public static void initDatabase() {
  18. String filename = "gen.db";
  19. String filepath = System.getProperty("user.dir") + "/" + filename;
  20. File dbFile = new File(filepath);
  21. if (!dbFile.exists()) {
  22. ClassPathResource resource = new ClassPathResource(filename);
  23. try {
  24. FileCopyUtils.copy(resource.getInputStream(), new FileOutputStream(dbFile));
  25. } catch (IOException e) {
  26. throw new RuntimeException("初始化数据库失败", e);
  27. }
  28. }
  29. }
  30. }