我想在URL中檢索多個變量,這樣我就可以將查詢發送到數據庫,以選擇一個特定的對象,但它似乎拿起的第一目標和其他均爲空。獲取的URL多變量JSON
@RequestMapping(value = "getGroup/{Name}/{StartDate}/{EndDate}/{Status_GroupID}", method = RequestMethod.GET)
public @ResponseBody List<GroupsDetails> getGroupList(
@PathVariable String Name, String StartDate, String EndDate,
Integer Status_GroupID) {
return musicStoreService.getGroupList(Name, StartDate, EndDate, Status_GroupID);
}
我recieving錯誤:
Hibernate: select groupsdeta0_.Status_GroupID as Status1_1_, groupsdeta0_.GroupsID as GroupsID1_, groupsdeta0_.EndDate as EndDate1_, groupsdeta0_.Name as Name1_, groupsdeta0_.StartDate as StartDate1_ from Groups groupsdeta0_ where groupsdeta0_.Name=Gamma and (groupsdeta0_.StartDate is null) and (groupsdeta0_.EndDate is null) and (groupsdeta0_.Status_GroupID is null)
Sep 12, 2014 2:41:40 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [SpringDispatcher] in context with path [/ATS] threw exception [Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'Gamma' in 'where clause'
表被命名組,它有行:名稱,開始日期,結束日期,Status_GroupID和GroupsID
更新:
我我試圖通過給出行的詳細信息來檢索主鍵,但它不起作用。
@Override
public List<GroupsDetails> getGroupList(String Name, String StartDate, String EndDate, Integer Status_GroupID) {
SessionFactory sessionFactory=HibernateSessionManager.getSessionFactory();
Session session=sessionFactory.getCurrentSession();
Transaction transaction=session.beginTransaction();
try{
transaction.begin();
@SuppressWarnings("unchecked")
List<GroupsDetails> groupList=session.createSQLQuery("FROM Groups WHERE Name=" + Name + " AND StartDate=" + StartDate + " AND EndDate=" + EndDate + " AND Status_GroupID=" + Status_GroupID).list();
return groupList;
}finally{
session.close();
}
}
但它拋出異常是嚴重的語法,甚至儘管我看不到在語法上的錯誤。 錯誤是:
Hibernate: FROM Groups WHERE Name=Gamma AND StartDate=01-06-2014 AND EndDate=01-09-2014 AND Status_GroupID=1
Sep 12, 2014 3:35:51 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [SpringDispatcher] in context with path [/ATS] threw exception [Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM Groups WHERE Name=Gamma AND StartDate=01-06-2014 AND EndDate=01-09-2014 AND' at line 1
謝謝你的工作,但現在我有另一個問題。如果可能的話你可以看看嗎? – Spinxas 2014-09-12 14:43:12