SpringBoot+MyBatis通过ScriptRunner读取SQL文件
@Component public class InitDBTables implements CommandLineRunner { @Autowired DataSource dataSource; //注入DataSource public void run(String... args) { ScriptRunner runner; try { runner = new ScriptRunner(dataSource.getConnection()); runner.setAutoCommit(true); runner.setStopOnError(true); //sql文件在scr/main/resources/scripts文件夹中 runner.runScript(Resources.getResourceAsReader("scripts/yourschema.sql")); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
作者:guanbin —— 纵码万里千山
出处:https://www.cnblogs.com/guanbin-529/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。