2011-01-27 17 views
3

SpringのAbstract Factoryパターンの実装に問題があります。抽象ファクトリメソッドのパターンを使用しない場合、うまく動作するSpring 3 MVCとHibernate 3を使用しています。 Factoryクラス(CategoryFactory)にアクセスするためにコントローラに何を追加する必要があるのか​​よくわかりません。抽象ファクトリメソッドのパターンがSpring MVCで動作しない

コントローラまたはBeanの開始に何か不足していますか?

class SectionsController extends MultiActionController { 
    /* Do I have to initiate the CategoryFactory here? */ 

    public ModelAndView secList() throws Exception { 
     CategoryFactory.CategoryType type = CategoryFactory.CategoryType.valueOf("view"); 
     modelMap.addAttribute("sectionList", CategoryFactory.findCategory(type).list(id)); 
     return new ModelAndView("Form", modelMap); 
    } 
} 

抽象工場

public abstract class Category { 
    public abstract List list(int departId); 
} 

public class CategoryFactory { 
    public enum CategoryType { firstclass, secondClass, ... } 
    public static Category findCategory(CategoryType categoryType) { 
     // Create type specific Category implementation 
    } 
} 
+0

一部*努力*試してみて、入れてくださいあなたの質問を書式設定することに。それは混乱です。 – skaffman

+0

私はコードを再フォーマットしました。 – mkohan

答えて

0

それことshoud:SectionsControllerはMultiActionController {

private HibernateTemplate hibernateTemplate; 

public void setSessionFactory(SessionFactory sessionFactory) { 
    this.hibernateTemplate = new HibernateTemplate(sessionFactory); 
} 

公共のModelAndView secList()は例外{ CategoryFactory.CategoryTypeタイプ= CategoryFactory.CategoryTypeをスロー延び クラス.valueOf( "view"); modelMap.addAttribute( "sectionList"、CategoryFactory.findCategory(タイプ)の.list(のHibernateTemplate、ID); リターン新しいのModelAndView( "フォーム"、modelMap);} }

関連する問題