所以我正在考虑使用Spring和JPA / Hibernate进行MySQL数据库访问,并看到了两种不同的方法。一个人有一个配置文件application.properties
# DataSource settings: set here your own configurations for the database
# connection. In this example we have "netgloo_blog" as database name and
# "root" as username and password.
spring.datasource.url = jdbc:mysql://localhost:8889/netgloo_blog
spring.datasource.username = root
spring.datasource.password = root
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
# Show or not log for each sql query
spring.jpa.show-sql = true
# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto = update
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager)
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
并且没有配置bean。它只是用于定义实体和控制器(源是http://blog.netgloo.com/2014/10/27/using-mysql-in-spring-boot-via-spring-data-jpa-and-hibernate/)
然后你得到了基本相同的应用程序,它有相同的application.properties(更短)文件,但也有一个配置bean,它定义了一个entitymanagerfactor并使用了entitymanger.persist而不是之前的一个使用repository.save()方法。 (http://blog.netgloo.com/2014/10/06/spring-boot-data-access-with-jpa-hibernate-and-mysql/)
我没有问到存储库和实体管理器之间的区别,我想知道为什么在application.properties旁边有一个单独的Java配置文件,并且必须通过所有的entitymanagerfactor代码。它没有实体管理器的代码少得多,那你为什么要用呢?
两个程序都做同样的事情,你访问localhost / create?user = name来在表中创建一个用户,使用相同的检索方法。
实体经理是否过时了?
由于