Spring Boot Jpa
2018-10-25 本文已影响0人
风雨楼兰
gradle配置
compile("org.springframework.boot:spring-boot-starter-data-jpa")
配置文件:
spring:
# security:
# user:
# name: lb
# password: 123456
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/db1?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&serverTimezone=GMT
username: root
password: 123456
hikari:
max-lifetime: 600000
maximum-pool-size: 20
connection-timeout: 30000
jpa:
show-sql: true
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
model定义:
@Entity
@Data
public class User implements Serializable{
@Id
private Long userId;
private String userName;
protected User(){}
}
dao定义:
public interface IUserDao extends Repository<User,Long> {
List<User> queryAllByUserName(String name);
}