最近在学习struts+spring+hibernate,在MyEclipse中自动创建持久化类Address,在Action中用DAO调用list方法显示数据库信息,
现在可以成功调用list方法但Hibernate给我返回的username是null(MySQL中有数据),所以jsp页面中显示不出数据库信息,请问这是什么原因造成的?这是DAO中的list方法 public class AddressDAO extends HibernateDaoSupport implements IAddressDAO {
public List findAllByUsername(final String username) {
return (List) getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException {
List result = session.createCriteria(Address.class).add(
Restrictions.eq("username", username)).list();
//System.out.println("111");
return result;
}
});
}
          …………
这是Action 中调用listpublic class AddressAction extends DispatchAction {
protected AddressDAO addressDAO;
Logger log = Logger.getLogger(this.getClass()); public AddressDAO getAddressDAO() {
return addressDAO;
} public void setAddressDAO(AddressDAO addressDAO) {
this.addressDAO = addressDAO;
} public ActionForward list(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String username = (String) request.getSession().getAttribute(
Constants.USERNAME_KEY); List list = addressDAO.findAllByUsername(username); request.setAttribute("addressList", list); ActionForward forward = mapping.findForward(Constants.LIST_KEY); return (forward);
}返回信息就是这样
null
Hibernate: select this_.ID as ID0_0_, this_.username as username0_0_, this_.name as name0_0_, this_.sex as sex0_0_, this_.mobile as mobile0_0_, this_.email as email0_0_, this_.qq as qq0_0_, this_.company as company0_0_, this_.address as address0_0_, this_.postcode as postcode0_0_ from address.address this_ where this_.username=?