帮助Spring3.0 MVC / Hibernate / HibernateDaoSupport集成

时间:2010-11-27 19:23:22

标签: hibernate spring-mvc

映射

< bean id =" signinDAO"类=" com.socialshop.authentication.dao.SigninDAOImpl">       < property name =" sessionFactory" REF =" mySessionFactory这个" />     < /豆腐>

DAO

public interface SigninDAO{
        public List<DataObject> getList();
}

public class SigninDAOImpl extends HibernateDaoSupport {
         public List<T> getList() {
  return (getHibernateTemplate().find("from " + dataClass.getName() + " x"));
 }
}

控制器

@Controller
@RequestMapping("/signin.html")
public class Signin {

 private SigninDAO signinDAO;
 Signin(){ 
 }

 public void setSigninDAO(SigninDAO signinDAO) {
  this.signinDAO = signinDAO;
 }

 @RequestMapping(method=RequestMethod.POST)
 public String processSubmit(@ModelAttribute("signinRequest") SigninRequest signinRequest,
   BindingResult result, SessionStatus status) {

  List<Merchant> merchant = signinDAO.getList();

   return "index";

 }

}

当我的登录表单被发布时,调用了processSubmit方法,我在这里得到空指针Exception List<Merchant> merchant = signinDAO.getList();

看起来setSigninDAO()方法未映射此请求?我该如何映射? 在这种情况下如何使用multiactioncontroller?

1 个答案:

答案 0 :(得分:2)

您需要使用@Autowired注释您的依赖项设置器方法:

@Autowired 
public void setSigninDAO(SigninDAO signinDAO) {   
    this.signinDAO = signinDAO;  
}

另见: