【发布时间】:2014-05-22 16:51:43
【问题描述】:
我查看了一些相关问题,但我仍然没有看到存储库和服务层之间有太大区别。所以给出的例子我想它应该是这样的,如果不是,请告诉我为什么?
public interface ProductRepository extends CrudRepository<Product, Long>{
public List<Product> findByName(String name);
public List<Product> findByPrice(Double price);
}
public interface ProductService {
public List<Product> findAll();
public Product findById(Long id);
public Product save(Product product);
public void delete(Product product);
public List<Product> findByName(String name);
public List<Product> findByPrice(Double price);
}
ProductService 的实现将使用 ProductRepository 来实现这些方法。正如我从http://docs.spring.io/spring-data/jpa/docs/1.3.0.RELEASE/reference/html/jpa.repositories.html 了解到的,来自存储库的方法查询是自动生成的。在我的示例中,方法在存储库和服务中重复,所以请说明需要更改什么/为什么需要更改?
【问题讨论】:
标签: java service repository data-access-layer