如何选择和显示自定义结果?

时间:2015-01-02 03:22:41

标签: hibernate jsf plsql

下面是 hibernate.reveng.xml 中的映射表列表:

  <table-filter match-name="UNI_MAJORS"/>
  <table-filter match-name="SKILLS"/>
  <table-filter match-name="PROFILES_JOB_EXPERIENCES"/>
  <table-filter match-name="PROFILES_EDU"/>
  <table-filter match-name="PROFILES_SKILLS"/>
  <table-filter match-name="UNI_DEGREES"/>
  <table-filter match-name="HIGHER_EDU_CENTERS"/>
  <table-filter match-name="COMPANIES"/>
  <table-filter match-name="PROFILES"/>
  <table-filter match-name="CITIES"/>
  <table-filter match-name="STATES"/>

我正在使用 *。hbm.xml 文件,而不是注释。 每件事情都正常工作我只想显示下面的结果,而不是上面映射的类:

select p.profile_id,pj.exp_id,p.full_name,ct.city_name
 ,c.company_name,pj.title,pj.date_from,pj.date_to
from PROFILES p
join PROFILES_JOB_EXPERIENCES pj on p.profile_id=pj.profile_ref
left outer join COMPANIES c on pj.company_ref=c.company_id
left outer join CITIES ct on ct.city_id=c.city_ref

我在控制器类中尝试了以下方法:

    @ManagedBean
    @ViewScoped
    public class ProfileExperiences implements Serializable {
      //code...(not need for display here)

      public List getExpList() {
      session = sessionFactory.openSession();
      transaction = session.beginTransaction();
      List<ProfileExpsView> lst = session.createQuery("Select p.profileId as profileId, pj.expId as expId,"
            + "p.fullName as fullName, cmp.cities.cityName as cityName,cmp.companyName as companyName,"
            + "pj.title as title,pj.dateFrom as dateFrom,pj.dateTo as dateTo "
            + "From Profiles p "
            + "join p.profilesJobExperienceses pj "
            + "join pj.companies cmp "
            + "where p.profileId=:p_profileId").setParameter("p_profileId",
            profiles.getProfileId()).list();
    transaction.commit();
    session.close();
    return lst;
    }
    //Code...(not need for display here)
  }

在我的JSF页面中我使用了这个:

<h:panelGrid>
            <h:dataTable id="expsList" value="#{profileExperiences.expList}" var="exp">
                <h:column>
                    <f:facet name="header">City</f:facet>
                    #{exp.cityName}
                </h:column>
                <h:column>
                    <f:facet name="hearde">Company</f:facet>
                    #{exp.companyName}
                </h:column>
                <h:column>
                    <f:facet name="header">Job Title</f:facet>
                    #{exp.title}
                </h:column>
                <h:column>
                    <f:facet name="header">Start Date</f:facet>
                    #{exp.dateFrom}
                </h:column>
                <h:column>
                    <f:facet name="header">End date</f:facet>
                    #{exp.dateTo}
                </h:column>
                <h:column>
                    <h:commandButton value="X" action="#{profileExperiences.deleteProExp(exp.expId)}">
                        <f:ajax execute="@form" render="@form"></f:ajax>
                    </h:commandButton>
                </h:column>
            </h:dataTable>
        </h:panelGrid>

但没有显示,问题是什么?

1 个答案:

答案 0 :(得分:0)

您可以返回List并使用索引

引用对象
 List<Object[]> lst = session.createQuery("Select cmp.cities.cityName as cityName,cmp.companyName as companyName,"
        + "pj.title as title,pj.dateFrom as dateFrom,pj.dateTo as dateTo "
        + "From Profiles p "
        + "join p.profilesJobExperienceses pj "
        + "join pj.companies cmp "
        + "where p.profileId=:p_profileId").setParameter("p_profileId",
        profiles.getProfileId()).list();

在JSF页面中,您可以参考#{item [0]} Refer here

<h:panelGrid>
        <h:dataTable id="expsList" value="#{profileExperiences.expList}" var="exp">
            <h:column>
                <f:facet name="header">City</f:facet>
                #{exp[0]}
            </h:column>
            <h:column>
                <f:facet name="hearde">Company</f:facet>
                 #{exp[1]}
            </h:column>
            <h:column>
                <f:facet name="header">Job Title</f:facet>
                #{exp[2]}
            </h:column>
            <h:column>
                <f:facet name="header">Start Date</f:facet>
                #{exp[3]}
            </h:column>
            <h:column>
                <f:facet name="header">End date</f:facet>
                #{exp[4]}
            </h:column>
            <h:column>
                <h:commandButton value="X" action="#{profileExperiences.deleteProExp(exp.expId)}">
                    <f:ajax execute="@form" render="@form"></f:ajax>
                </h:commandButton>
            </h:column>
        </h:dataTable>
    </h:panelGrid>