SpringBoot整合之Spring Data JPA (CRUD,分页,动态条件查询)

一个Java小白的学习之路 个人博客 youngljx.top

Spring Data JPA

Spring Data JPA是Spring基于ORM框架、JPA规范的基础上封装的一套JPA应用框架,是基于Hibernate之上构建的JPA使用解决方案,用极简的代码实现了对数据库的访问和操作,包括了增、删、改、查等在内的常用功能.

SpringBoot整合Spring Data JPA

pom文件添加依赖
   <!-- 配置mysql数据库连接驱动 -->
  <dependency>
       <groupId>mysql</groupId>
       <artifactId>mysql-connector-java</artifactId>
  </dependency>
  
    <!-- 配置jpa依赖 -->
   <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
   </dependency>
properties配置文件
 #数据库连接池配置 时区时间是本地时间
 spring.datasource.url=jdbc:mysql://localhost:3306/mysql1
 ?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=GMT%2B8 
 
   #注意新版本driver使用:com.mysql.cj.jdbc.Driver 否则会异常
   spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
   spring.datasource.username=root
   spring.datasource.password=qwert
   spring.datasource.tomcat.initial-size=10
   spring.datasource.tomcat.max-active=20
   spring.datasource.tomcat.max-idle=8
   spring.datasource.tomcat.min-idle=8
   
 #jpa相关配置
  spring.jpa.database = mysql
  spring.jpa.show-sql = true
  spring.jpa.hibernate.ddl-auto = update
  spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
  spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.MySQL5Dialect
  spring.jpa.open-in-view=false
编写实体类Bean
  • 编写公共实体类BaseBean
/**
 * @description: 描述实体类的共同配置
 * @date: 2020-03-11 12:58
 */

@Data
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class BaseBean {
   
    /**
    * @Description: 自增长id
    * @Date: 2020/3/11-14:11
    */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;


    /**
     * @Description:创建时间
     * @Date: 2020/3/10-22:17
            */
    @CreatedDate
    @Column(nullable = false ,updatable = false)
    protected Date createTime;

    /**
     * @Description: 修改时间
     * @Date: 2020/3/10-22:17
     */
    
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值