spring boot - 整合jpa

Posted 快猜猜我是谁

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring boot - 整合jpa相关的知识,希望对你有一定的参考价值。

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
     
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.10</version>
        </dependency>
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driverClassName= com.mysql.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
@Entity
@Table(name="t_user")
public class JpaUser {
    @Column(name="name")
    private String name ;
    @Column(name="address")
    private String address ;
    @Column(name="id")
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id ;
    @Column(name="age1")
    private Integer age ;
    @Column(name="age11")
    private  Integer age1 ;

    public JpaUser(String name, String address, Integer age, Integer age1,Integer id) {
        this.name = name;
        this.address = address;
        this.age = age;
        this.age1 = age1;
        this.id = id;
    }

    public JpaUser() {
    }
}
public interface JpaUserRespotory extends JpaRepository<JpaUser,Integer> {
}
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = springBoot.class)
public class JpaTest {
    @Autowired
    JpaUserRespotory jpaUserRespotory ;
    @Test
    public void test1 () {
        JpaUser jpaUser = new JpaUser("名称","地址",10,20,40);
        jpaUserRespotory.save(jpaUser);
    }
}

 

以上是关于spring boot - 整合jpa的主要内容,如果未能解决你的问题,请参考以下文章

Spring Boot 整合 JPA 使用多个数据源

Spring Boot 整合Spring Data JPA

spring boot整合spring Data JPA和freemarker

spring boot - 整合jpa

Spring Boot:整合Spring Data JPA

Spring Boot整合Spring Data JPA