springboot之hibernate之helloworld
springboot引入hibernate是通过spring-boot-starter-data-jpa,并没有一个spring-boot-starter-hibernate。
然后再引入mysql的connector就可以了。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
数据库的登录信息配置在src/resources/application.properties里:
spring.application.name=test-hibernate
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=1234
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
语法简单但是奇奇怪怪。
要先在数据库创建一个叫test的database,这样就能运行了。
最后配置: win10 mysql8.4 spring-build-tool4.28