0
我必须使用Spring 3 MVC,Spring数据和JPA开发业务应用程序。我搜索了一些例子,我发现了一些解决方案。我选择了两种方法来设计我的webapp。第一个是(例如用于一个实体):Spring MVC + Spring数据应用模型
@Entity
class Product {
//fields, methods
}
interface ProductRepository extends JpaRepository <Product, Long>{}
interface ProductService {
//methods declaration
}
@Service
class ProductServiceImpl implements ProductService{
@Autowired
ProductRepository
//methods
}
@Controller
@RequestMapping("productsite")
class ProductController{
@Autowired
ProductServiceImpl
//render the model
}
和第二:
@Entity
class Product {
//fields, methods
}
interface ProductRepository extends JpaRepository <Product, Long>{
//methods declaration
}
@Service
class ProducDAO{
@Autowired
ProductRepository
//methods
}
@Component
class ProductEndpoint{
@Autowired
ProducDAO
//fields, methods
}
@Controller
@RequestMapping("productsite")
class ProductController{
@Autowired
ProductEndpoint
//render the model
}
哪种溶液为更好,按照好的做法呢?感谢帮助。
DAO和存储库基本上是一样的东西。我没有看到任何存储库使用DAO的理由。这两个部分的责任是什么?另外,当一个组件有一个接口和一个实现时,接口必须是自动装配的,而不是实现。 –