javax.el.PropertyNotFoundException:类' java.lang.String'没有财产' salaryNo'

时间:2014-07-15 17:48:23

标签: java class exception jstl el

请解决我获得不同薪水的问题

PayrollController.java

public ModelAndView SalaryNoPopup(HttpServletRequest req, HttpServletResponse res)  {

   ModelMap modelMap = new ModelMap();
   modelMap.addAttribute("GensalarystructureLst",payrollsystemdao.GensalarystructureList());
   return new ModelAndView("SalaryNoPopup", modelMap);
}

PayrollDAO.java

public List<Gensalarystructure> GensalarystructureList(){

   List<Gensalarystructure> salary = null;
   Transaction tx=null;
   Session session = getSessionFactory().openSession();
    try
    {
      tx = session.beginTransaction();
      salary=session.createQuery(" select distinct salaryNo from Gensalarystructure " + " where status!='Inactive'").list();    
      tx.commit();
    }catch(HibernateException e){
    }finally{
      session.close();
    }
   return salary;
}

SalaryNopopup.jsp

<tbody>
   <c:forEach items="${GensalarystructureLst}" var="salary">
   <tr>
     <td><c:out value="${salary.salaryNo}"/></td>

   </tr>
   </c:forEach>
</tbody>

Gensalarystructure.java

public class Gensalarystructure implements java.io.Serializable {
   private String salaryNo;
   private String status;
   public String getStatus() {
    return this.status;
   }

   public void setStatus(String status) {
     this.status = status;
   }
   public String getSalaryNo() {
    return this.salaryNo;
   }

   public void setSalaryNo(String salaryNo) {
    this.salaryNo = salaryNo;
   }
}

这里的问题是 thePropertyNotFoundException 。它没有在页面中显示任何值。

每当我将查询更改为:

salary=session.createQuery("from Gensalarystructure " + "where status!='Inactive'").list();

然后它的工作绝对正常。但我需要salaryNo进入已排序的format.so我使用下面的查询然后它开始抛出错误。

salary=session.createQuery("select distinct salaryNo from Gensalarystructure " + " where status!='Inactive'").list();

2 个答案:

答案 0 :(得分:1)

您只在DAO中选择List<String>

salary=session.createQuery(" select distinct salaryNo from Gensalarystructure "
+ " where status!='Inactive'").list();  

将其更改为

Criteria criteria = (Criteria) session.
              createCriteria(Gensalarystructure.class).
criteria.setProjection(Projections.distinct(Projections.property("salaryNo")));
salary = criteria.list()

答案 1 :(得分:0)

## PayrollDAO.java ##

  public List<Gensalarystructure> GensalarystructureList(){

    System.out.println("SalaryList");
    List<Gensalarystructure[]> salary = null;
    Transaction tx = null;
    Gensalarystructure ob =null;
    Session session = getSessionFactory().openSession();
    Query query = null;
    List<Gensalarystructure> list = new ArrayList<Gensalarystructure>();
    try {
        tx = session.beginTransaction();
            query = session.createQuery("SELECT distinct salaryNo,userId FROM Gensalarystructure");      
            salary = query.list();
            System.out.println("list salary "+salary);                
              for(Object[] objArr: salary){
                        ob=new Gensalarystructure();
                        ob.setStructureNo(((String)(objArr[0])));
                        ob.setStructureCode((String)(objArr[1]));

                        list.add(ob);

                    }   

        tx.commit();
    } catch (HibernateException e) {
        if (tx != null) {
            tx.rollback();
        }
        e.printStackTrace();
    }  finally {
        session.close();
    }

    return list;
}

大家好,salaryno属性值没有标识,因此在将列表对象发送到JSTL视图页面之前,我使用了setter方法使用迭代器分配属性。 然后,JSTL可以确定特定的财产,并且它按预期工作。

谢谢大家的支持。 希望这个答案有所帮助。