在Spring Boot中执行DDL语句有多种方式,以下是其中两种常用的方式:
示例代码:
@Autowired
private JdbcTemplate jdbcTemplate;
public void executeDDL() {
String ddlSQL = "CREATE TABLE my_table (id INT PRIMARY KEY, name VARCHAR(100))";
jdbcTemplate.execute(ddlSQL);
}
示例代码:
@Autowired
private SessionFactory sessionFactory;
public void executeDDL() {
SchemaExport schemaExport = new SchemaExport(sessionFactory);
schemaExport.create(true, true);
}
以上两种方式都可以在Spring Boot中执行DDL语句,你可以根据自己的需求选择合适的方式。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:mybatis怎么执行ddl语句