Spring Boot Jpa

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);
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容