【视频 & 交流平台】
http://study.163.com/course/introduction.htm?courseId=1004329008&utm_campaign=commission&utm_source=400000000155061&utm_medium=share
http://study.163.com/course/introduction.htm?courseId=1004638001&utm_campaign=commission&utm_source=400000000155061&utm_medium=share
https://gitee.com/happyangellxq520/spring-boot
http://412887952-qq-com.iteye.com/blog/2321532
网易云课堂视频最新更新:
第十一章 Spring Boot 日志
1、spring boot日志—理论
2、Spring Boot日志-logback
3、Spring Boot日志-log4j2
第十二章 Spring Boot 知识点2
1、spring boot 服务配置和部署
2、Spring Boot 定制URL匹配规则
在说具体如何在spring boot 使用Hibernate前,先抛装引玉些知识点?什么是JPA呢?
JPA全称Java Persistence API.JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中。
接下里就说本文章重点了,那么怎么操作呢?只需要如下配置就可以了?
pom.xml配置:
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency>
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>
application.properties配置:
######################################################## ###datasource ######################################################## spring.datasource.url = jdbc:mysql://localhost:3306/test spring.datasource.username = root spring.datasource.password = root spring.datasource.driverClassName = com.mysql.jdbc.Driver spring.datasource.max-active=20 spring.datasource.max-idle=8 spring.datasource.min-idle=8 spring.datasource.initial-size=10 ######################################################## ### Java Persistence Api ######################################################## # Specify the DBMS spring.jpa.database = MYSQL # 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 # stripped before adding them to the entity manager) spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
那么就可以使用Hibernate带来的好处了,在实体类注解@Entity就会自动进行表的DDL操作了。
我们在com.kfit.test.bean.Demo 中加入注解:@Entity
@Entity//加入这个注解,Demo就会进行持久化了,在这里没有对@Table进行配置,请自行配置。 public class Demo { @Id @GeneratedValue private long id;//主键. private String name;//测试名称. //其它代码省略.
这时候运行就会在数据库看到demo表了。
【视频&交流平台】
http://study.163.com/course/introduction.htm?courseId=1004329008
http://study.163.com/course/introduction.htm?courseId=1004638001
https://gitee.com/happyangellxq520/spring-boot
http://412887952-qq-com.iteye.com/blog/2321532
网易云课堂视频最新更新:
第十一章 Spring Boot 日志
1、spring boot日志—理论
2、Spring Boot日志-logback
3、Spring Boot日志-log4j2
第十二章 Spring Boot 知识点2
1、spring boot 服务配置和部署
2、Spring Boot 定制URL匹配规则