1.JpaRepository
创建dao层 ==ProductCategoryRepository==接口,必须实现==JpaRepository<映射对象,主键类型>== 接口
package cn.xiaochi.dao;
import cn.xiaochi.dataobject.ProductCategory;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ProductCategoryRepository extends JpaRepository<ProductCategory, Integer> {
}
==CRUDRepository== 继承==Repository==
==PagingAndSortingRepository== 继承==CRUDRepository==
==JpaRepository== 继承==PagingAndSortingRepository==
意味着只需继承接口JpaRepository, 便有了以上所有接口的功能
image.pngimage.png
2.@RepositoryDefinition注解
package cn.xiaochi.dao;
import cn.xiaochi.dataobject.ProductCategory;
import org.springframework.data.repository.RepositoryDefinition;
@RepositoryDefinition(domainClass = ProductCategory.class,idClass = Integer.class)
public interface ProductCategoryRepository {
}
网友评论