// 根据配置生成表结构
@Test
public void test() throws Exception {
Configuration cfg = new Configuration().configure();
SchemaExport schemaExport = new SchemaExport(cfg);
// 第一个参数script的作用: print the DDL to the console
// 第二个参数export的作用: export the script to the database
schemaExport.create(true, true);
}
第一个参数的作用是判断是否将DDL即建表等语句打印到控制台
第二个参数的作用是判断是否执行对应的DDL语句
此外除了这种方式,也可以用配置文件 的方式来生成表结构
<property name="hbm2ddl.auto">update</property>
<property name="hbm2ddl.auto">create</property>