我正在尝试将日期参数传递给我的应用程序,但我遇到了一些困难我的 DAO 看起来像这样:
@Override
public List <Object[]>getMontantParVehicule(Date d1,Date d2) {
Session session=HibernateUtil.getSessionFactory().openSession();
try{
session.beginTransaction();
System.out.println("Stat HQL");
SQLQuery q=session.createSQLQuery("select IMMAT,SUM(PRIX) as COUT,SUM(QUANTITE) as QUANTITE,COUNT(IMMAT) as nbre from BON_ESSENCE where DATE_BON between :debut and :fin GROUP BY IMMAT ");
// Query q =session.createQuery("select immat,sum(prix) as mnt from BonEssence group by immat ");
q.setParameter("debut",d1 );
q.setParameter("fin",d2 );
return q.list();
}catch (RuntimeException e) {
session.getTransaction().rollback();
throw e;
}finally{
session.getTransaction().commit();
}
}
和
private Date d1;
private Date d2;
public Date getD1() {
return d1;
}
public void setD1(Date d1) {
this.d1 = d1;
}
public Date getD2() {
return d2;
}
public void setD2(Date d2) {
this.d2 = d2;
}
public List<Object[]> getMontantParVehiculeTotal(){
return essenceService.getMontantParVehicule(d1, d2);
}
我的 xhtml 页面如下所示:
<h:panelGrid columns="2" id="grid2">
<h:outputLabel value=" debut: *" for="txt_d1" />
<p:calendar locale="fr" value="#{bonEssenceBean.d1}" id="txt_d1" datePattern="dd/yyyy/MM" required="true" ></p:calendar>
<h:outputLabel value=" Fin: *" for="txt_d2" />
<p:calendar locale="fr" value="#{bonEssenceBean.d2}" id="txt_d2" datePattern="dd/yyyy/MM" required="true" ></p:calendar>
<p:button id="btn_add" value="Enregistrer"
outcome="DetailBon" >
<f:param name="d1" value="#{bonEssenceBean.d1}"></f:param>
<f:param name="d2" value="#{bonEssenceBean.d2}"></f:param>
</p:button>
</h:panelGrid>
和
<ui:composition template="/Views/Template/common.xhtml">
<ui:define name="Edition">
<h:form id="form">
</h:form>
</ui:define>
<ui:define name="Consultation">
<h:form id="form2">
<!-- //////////////////////////////////////////////////////////////////////////// -->
<p:dataTable id="statTable" var="item" value="#{bonEssenceBean.montantParVehiculeTotal}" widgetVar="statTable" sortMode="single" rows="5" paginator="true" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,15,25">
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search:" style="Height:30px"/>
<p:inputText id="globalFilter" onkeyup="carsTable.filter()" style="width:150px" />
</p:outputPanel>
</f:facet>
<p:column headerText="Vehicule" >
<h:outputText value="#{item[0]}" />
</p:column>
<p:column headerText="COUT">
<h:outputText value="#{item[1]}" />
</p:column>
<p:column headerText="QUANTITE">
<h:outputText value="#{item[2]}" />
</p:column>
<p:column headerText="Nombre de bon">
<h:outputText value="#{item[3]}" />
</p:column>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
</html>
我认为这是因为我的参数没有正确传递给 SQL 请求。有人可以帮我吗?