SSH执行一个复合查询
做一个SSH的开发,项目是飞机 订票系统。写到了查找航班的模块,要求是在页面输入目的地以及起飞的时间,然后输出同时满足输入的目的地以及起飞时间的一条航班信息。
FlightQueryTarget.jsp
HTTP Status 500 - Unknown entity: from Flight as fli where fli.f_location=? and fli._time=? ; nested exception is org.hibernate.MappingException: Unknown entity: from Flight as fli where fli.f_location=? and fli._time=?
求大神解答,很重要的项目。新手自己从零动手,不容易。求解答,不求打劫
就是这个模块,我在DAO类写了一个复合查询的方法
//按目的地,起飞时间进行查询 public Flight queryByLocationAndTime(String f_location, String f_time) { // TODO Auto-generated method stub String hql= "from Flight as fli where fli.f_location=? and fli._time=? "; List<Flight> entitise=getHibernateTemplate().findByExample(hql,new String[]{"f_location","f_time"}); if (entitise.size() > 0) { Flight entity = entitise.get(0); return entity; } return null; }
然后在Service类写了逻辑处理的方法
public Flight queryFlightScheduledByLocationAndTime(String f_location, String f_time) { // TODO Auto-generated method stub if(f_location!=null&&f_time!=null){ return dao.queryByLocationAndTime(f_location, f_time); }else{ System.out.println("不存在目标航班"); } return null; }
package com.air.action; import java.util.Date; import com.air.po.Flight; import com.air.service.FlightService; import com.opensymphony.xwork2.ActionSupport; public class FlightQueryTargetAction extends ActionSupport{ private String f_location; private String f_time; //业务逻辑组件 private FlightService fs; //设置业务逻辑组件 public void setFlightService(FlightService fs){ this.fs=fs; } public String getF_location() { return f_location; } public void setF_location(String f_location) { this.f_location = f_location; } public String getF_time() { return f_time; } public void setF_time(String f_time) { this.f_time = f_time; } public String execute()throws Exception{ //将接受的参数设置到Product实例中 Flight f=new Flight(); f.setF_location(f_location); f.setF_time(f_time); //调用业务逻辑组件保存该产品 fs.queryFlightScheduledByLocationAndTime(f_location, f_time); return SUCCESS; } }
package com.air.action; import java.util.Date; import java.util.List; import org.apache.struts2.ServletActionContext; import com.air.po.Flight; import com.air.service.FlightService; import com.opensymphony.xwork2.ActionSupport; public class FlightShowTargetAction extends ActionSupport{ private String f_location; private String f_time; //业务逻辑组件 private FlightService fs; //设置业务逻辑组件 public void setFlightService(FlightService fs){ this.fs=fs; } public String getF_location() { return f_location; } public void setF_location(String f_location) { this.f_location = f_location; } public String getF_time() { return f_time; } public void setF_time(String f_time) { this.f_time = f_time; } public String execute()throws Exception{ //通过调用业务逻辑组件获得所有的产品 List <Flight>tag=(List<Flight>) fs.queryFlightScheduledByLocationAndTime(f_location, f_time); //将所有产品List存储在request范围中 ServletActionContext.getRequest().setAttribute("tag",tag); return SUCCESS; } }
<action name="flightquerytarget" class="flightQueryTargetAction"> <!-- 定义处理结果与试图资源之间的关系 --> <result name="success" type="redirect">flightshowtarget.action</result> </action> <action name="flightshowtarget" class="flightShowTargetAction"> <!-- 定义处理结果与试图资源之间的关系 --> <result name="success">/FlightShowTarget.jsp</result> </action>
<!-- 创建FlightQueryTargetAction实例 --> <bean id="flightQueryTargetAction" class="com.air.action.FlightQueryTargetAction" scope="prototype"> <property name="flightService" ref="flightService"></property> </bean> <!-- 创建FlightShowTargetAction实例 --> <bean id="flightShowTargetAction" class="com.air.action.FlightShowTargetAction" scope="prototype"> <property name="flightService" ref="flightService"></property> </bean>
FlightQueryTarget.jsp
<s:form action="flightquerytarget" method="post"> <s:textfield label="航班起飞时间" name="f_time"></s:textfield> <s:textfield label="航班目的地" name="f_location"></s:textfield> <s:submit value="提交"></s:submit> <s:reset value="重置"></s:reset> </s:form>
<s:iterator value="#request.tag" id="flight"> <tr> <td><s:property value="#flight.f_id"/></td> <td><s:property value="#flight.f_time"/></td> <td><s:property value="#flight.f_price"/></td> <td><s:property value="#flight.f_location"/></td> <td><s:property value="#flight.f_sitnum"/></td> <td><a href="OrderTicket.jsp">订票</a></td> </tr> </s:iterator>
HTTP Status 500 - Unknown entity: from Flight as fli where fli.f_location=? and fli._time=? ; nested exception is org.hibernate.MappingException: Unknown entity: from Flight as fli where fli.f_location=? and fli._time=?
求大神解答,很重要的项目。新手自己从零动手,不容易。求解答,不求打劫
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
补充一点,po类和Flight,hbm.xml等配置不会出现问题的,因为已经测试过输出全部航班信息。所以Hibernate持久化那边应该没问题。。。