Goods goods = new Goods();
goods.setName("电脑");
System.out.println(goods);
//获取goodsDAO
GoodsDAOImpl goodsDAO = (GoodsDAOImpl)factory.getBean("goodsDAO");
System.out.println(goodsDAO.findByExample(goods));输出结果是:
id=null | name=电脑 | price=null | time=null
[id=1005 | name=电脑 | price=2000.0 | time=2012-04-02]也就是说通过findByExample通过name查找到了对应的数据但是在action中System.out.println(goods.getName()+"goods="+goods);
System.out.println(goodsDAO.findByName(goods.getName()));
System.out.println(goodsDAO.findByExample(goods));输出结果为:
电脑goods=id=null | name=电脑 | price=null | time=null
[id=1005 | name=电脑 | price=2000.0 | time=2012-04-02]
[]求解,而且System.out.println(goods.getName()+"goods="+goods);这段代码表明我已经获取到了从jsp页面传递进来的参数,同样的方法,为什么在测试类里面和action里面得到的结果却不相同?

解决方案 »

  1.   

    public List findByExample(Goods instance) {
    log.debug("finding Goods instance by example");
    try {
    List results = getHibernateTemplate().findByExample(instance);
    log.debug("find by example successful, result size: "
    + results.size());
    return results;
    } catch (RuntimeException re) {
    log.error("find by example failed", re);
    throw re;
    }
    }
      

  2.   

    你把查询的sql语句打印出来,用hibernate的那个打印语句