我想按name查询在hibernate中用HQL怎么实现??要是用findByProperty这儿方法怎么实现??、

解决方案 »

  1.   

    映射:
     <property name="userName" type="java.lang.String">
         <column name="USER_NAME" length="20"/>
     </property>    dao:
       public List findByProperty(String propertyName, Object value) {
          log.debug("finding User instance with property: " + propertyName
                + ", value: " + value);
          try {
             String queryString = "from User as model where model." 
              + propertyName + "= ?";
     return getHibernateTemplate().find(queryString, value);
          } catch (RuntimeException re) {
             log.error("find by property name failed", re);
             throw re;
          }
       }
    调用:List list = findByProperty("userName", "姓名") ;
      

  2.   

    public List<Zone> findByProperty(String propertyName, Object value) {
    log.debug("finding Zone instance with property: " + propertyName
    + ", value: " + value);
    try {
    String queryString = "from Zone as model where model."
    + propertyName + "= ?";
    Query queryObject = getSession().createQuery(queryString);
    queryObject.setParameter(0, value);
    return queryObject.list();
    } catch (RuntimeException re) {
    log.error("find by property name failed", re);
    throw re;
    }
    }
    Serviceimpl中我不知道怎么给参数
    public List<Zone> findByProperty(String propertyName, Object value)
    throws Exception {
    // TODO Auto-generated method stub
    return zoneDAO.findByProperty(propertyName, propertyName);
    }还有在action中我不知道怎么给参数
      

  3.   

    List list = findByProperty("userName", "姓名")
    user 指的是什么啊?还有姓名?
      

  4.   


    (String propertyName, Object value)
    propertyName 传你的Zone类中对应的你要查的字段的名称,value 传你要查的条件的值