spring-boot spring-data-jpa 使用

spring-boot spring-data-jpa 使用,第1张

spring-boot spring-data-jpa 使用

依赖

 
            org.springframework.boot
            spring-boot-starter-data-jpa
        
        
            org.projectlombok
            lombok
            1.18.12
        

配置

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/duidui?charset=utf8mb4&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456

spring.datasource.hikari.maximum-pool-size=200
spring.datasource.hikari.minimum-idle=50

spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=create

entity


import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.*;

@Entity
@Table(name = "dataexchange_task")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TaskDO {

    @Id
    @Column(name = "task_id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long taskID;


    
    private Date taskStartTime;

    
    private String serviceID;

    
    private Integer status;

    
    private int isDelete;

    
    private Integer version;
}

dao

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import paas.dao.model.TaskDO;

@Repository
public interface TaskDao extends JpaRepository {
    @Query(value = "SELECT * FROM dataexchange_task t WHERe t.status = ?1 AND t.is_delete = ?2 ",
            countQuery = "SELECT count(*) FROM dataexchange_task t WHERe t.status = ?1 AND t.is_delete = ?2",
            nativeQuery = true)
    public Page findUnExecuteTask(int status ,int  isDelete, Pageable pageable);
}

启动

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication(scanbasePackages = "paas")
@EnableJpaRepositories("paas.dao")
@EntityScan("paas.dao.model")
public class WebApiApplication {

    public static void main(String[] args)  {
        SpringApplication.run(WebApiApplication.class, args);
    }

}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5671331.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存