我在android培训中心网站上看到了这段代码:
boolean hasExternalStoragePrivateFile() {
// Get path for the file on external storage. If external
// storage is not currently mounted this will fail.
File file = new File(getExternalFilesDir(null), "DemoFile.jpg");
if (file != null) {
return file.exists();
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
这是否意味着在Android上new File()可以返回null?
我有Spring JPA,Hibernate,MySQL的问题.我有一个实体(Nom.java)和存储库(公共接口NomRepository扩展JpaRepository).它们被创建并注入很好.
问题在于,当我试图通过存储库的save方法保存记录时,spring抱怨"Table"不存在".实际上我没有在MySQL中看到这个表.你已经尝试了不同的hibernate.hbm2ddl.auto值,但它没有帮助.
我使用无XML配置BTW.
这是配置文件:
package ru.interosite.awp.config;
import java.util.Properties;
import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
@Configuration
@ComponentScan("ru.interosite.awp")
@EnableAutoConfiguration
public class AppConfiguration {
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/awp");
dataSource.setUsername("root");
dataSource.setPassword("password");
return dataSource;
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {
LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
lef.setPersistenceUnitName("my_pu");
lef.setPackagesToScan("ru.interosite.awp.data");
lef.setDataSource(dataSource);
lef.setJpaVendorAdapter(jpaVendorAdapter);
lef.setJpaProperties(getJpaProperties());
return lef;
}
@Bean
public JpaVendorAdapter jpaVendorAdapter() …Run Code Online (Sandbox Code Playgroud)