我正在通过以下代码创建数据库表:
public void createSchema() {
Configuration configuration = new Configuration();
configuration.setProperty("hibernate.connection.driver_class", driverClassName);
configuration.setProperty("hibernate.connection.url", url);
configuration.setProperty("hibernate.connection.username", username);
configuration.setProperty("hibernate.connection.password", password);
configuration.setProperty("hibernate.dialect", hibernateDialect);
configuration.addAnnotatedClass(Base.class);
configuration.addAnnotatedClass(User.class);
logger.info("begin database schema creation =========================");
new SchemaUpdate(configuration).execute(true, true);
logger.info("end database schema creation ===========================");
}
在这里,我按configuration.addAnnotatedClass
方法指定了带注释的类名称。如果我有 50 节课,那真的会很乱。
有没有办法指定包名称以扫描带注释的类?