我想刷新我的数据,为此我有以下方法
@RequestMapping(value = "/add", method = RequestMethod.POST)
@Transactional
public String musicSubmit(@ModelAttribute Music music, Model model) {
musicRepository.saveAndFlush(music);
model.addAttribute("music", music);
return "result";
}
我的模型
public interface MusicRepository extends JpaRepository<Music, Integer> {
}
我的主要
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
我的数据是可见的,但如果我关闭应用程序并再次运行,即使我像这样设置 applications.properties,它们也会消失
spring.jpa.hibernate.ddl-auto = update
即使关闭应用程序或重新启动计算机,如何保留我的数据?
最佳答案
在application.properties
中使用这些:
spring.datasource.url = jdbc:h2:file:~/some_path/YourVeryDbFile
spring.datasource.username = sa
spring.datasource.password =
spring.datasource.driverClassName = org.h2.Driver
spring.jpa.database = H2
spring.jpa.show-sql = true
请注意,这使用了H2;如果您想要其他内容(MYSQL),您应该以其他方式指定它(并相应地更改值)。
看看here .
关于java - JPA + Hibernate + CrudRepository 刷新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29378329/