2013-07-27 36 views
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 
} 

哪種溶液爲更好,按照好的做法呢?感謝幫助。

+0

DAO和存儲庫基本上是一樣的東西。我沒有看到任何存儲庫使用DAO的理由。這兩個部分的責任是什麼?另外,當一個組件有一個接口和一個實現時,接口必須是自動裝配的,而不是實現。 –

回答

0

開始儘可能簡單。我認爲第一個解決方案對大多數Web應用程序來說已經足夠了

+0

感謝您的建議。 – user978758