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();
        }

    }
}

 

上一篇:create-react-app 工程,如何修改react端口号


下一篇:【OH】常用数据字典脚本说明 SQL Scripts