美文网首页
在SpringBoot中使用hibernate

在SpringBoot中使用hibernate

作者: 42个艾尔 | 来源:发表于2019-03-28 09:41 被阅读0次

    1.首先进行application.yml 的配置

    spring:
      datasource:
        type: com.zaxxer.hikari.HikariDataSource
        url: jdbc:mysql://localhost/test?serverTimezone=UTC&characterEncoding=utf-8
        username: root
    
        driver-class-name: com.mysql.cj.jdbc.Driver
        hikari:
          minimum-idle: 3
          idle-timeout: 100000
      jpa:
        show-sql: true
        hibernate:
          ddl-auto: update
    

    2.对domin的类进行配置

    @Entity(name = "countries")
    /*配置json,注意设立自增长后需要单独加入注解
      @GeneratedValue(strategy=GenerationType.AUTO)*/
    @JsonIgnoreProperties(value = {"hibernateLazyInitializer","handler"})
    public class Countries {
        @Id
        @Column(name = "country_id")
        private Integer countryId;
        @Column(name = "country_name")
        private String countryName;
        @Column(name = "region_id")
        private Integer regionId;
    

    3.对Mapper进行配置

    @Repository
    public interface CountryDao  extends JpaRepository<Countries,Integer> {
    
    }
    //分页
    @Repository
    public interface MerchantsDao extends PagingAndSortingRepository<Merchants,Integer> {
        Page<Merchants> findByMerchantsName(String name, Pageable pageable);
    }
    

    相关文章

      网友评论

          本文标题:在SpringBoot中使用hibernate

          本文链接:https://www.haomeiwen.com/subject/egyfbqtx.html