SpringBoot入门(六)-Spring D…

来源:互联网 发布:docker mysql 持久化 编辑:程序博客网 时间:2024/06/11 20:05

Spring Data JPA仓库repositories)是用来定义访问数据的接口。根据你的方法名,JPA查询会被自动创建。比如,一个

CityRepository接口可能声明一个findAllByState(Stringstate)方法,用来定状的所有城市。

于比查询,你可以使用SpringDataQuery来注解你的方法。

Spring Data仓库通常承自RepositoryCrudRepository接口。如果你使用自配置,包括在你的主配置(被

@EnableAutoConfiguration@SpringBootApplication注解的)的包下的仓库将会被搜索。

下面是一个传统SpringData仓库

package com.example.myapp.domain;

import org.springframework.data.domain.*;

import org.springframework.data.repository.*;

public interface CityRepository extends Repository<</span>City,Long>{

Page findAll(Pageablepageable);

City findByNameAndCountryAllIgnoringCase(Stringname, String country);

}

注:我们仅仅触及了SpringData JPA的表面。具体看它的参考指南

http://projects.spring.io/spring-data-jpa/

0 0
原创粉丝点击