springboot 集成 jpa 详解

采用maven配置

项目结构:
springboot 集成 jpa 详解_第1张图片

添加相关依赖

        
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-data-jpaartifactId>
        dependency>

        
        <dependency>
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
        dependency>
        <dependency>

application.yml

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/test
    username: root
    password: root
    driver-class-name: com.mysql.jdbc.Driver
  jpa: 
    properties:
      hibernate: 
        hbm2ddl.auto: create-drop

UserRepository

public interface UserRepository extends JpaRepository<User,Integer> {

    @Query("From User")
    public List findTest(); 

    public List findByUsernameLike(String username);
}

更多查询规则 详情见 jpa查询详解

项目源码下载

你可能感兴趣的:(SpringBoot)