Recently some learning MongoTemplate usage, you see the younger brother of the error message follows.
@ Override
Public ListThe list (String studioCode, String studentCode, PageBean PageBean, Date startTime,
The Date the endTime) {
Query Query=new Query ();
if(! StringUtils. IsEmpty (studioCode)) {
Query. AddCriteria (new Criteria (" studioCode "), is (studioCode));
}
if(! StringUtils. IsEmpty (studentCode)) {
Query. AddCriteria (new Criteria (" studentCode "), is (studentCode));
}
If (startTime!=null) {
Query. AddCriteria (new Criteria (" attendanceTime "). Gte (startTime));
}
If (endTime!=null) {
Query. AddCriteria (new Criteria (" attendanceTime ".) lt (endTime));
}
Query. Skip (pageBean getStart ()). The limit (pageBean) getPageSize ());
Return catsMongoTemplate. Find (query, Attendance. Class);
}
Then the error message is as follows:
org. Springframework. Data. The mongo. InvalidMongoDbApiUsageException: Due to limitations of the com. The mongo. BasicDBObject, you can 't add a second attendanceTime' criteria. The Query already contains' {" attendanceTime ": {" $gte" : {" $date ":" the 2016-10-31 T16:00:00. 000 z "}}} '.
Org. Springframework. Data. The mongo. Core. Query. The query. AddCriteria (99) query. Java:
Com. Hx. Dao. Studio. Attendance. Impl. AttendanceDaoImpl. List (46) AttendanceDaoImpl. Java:
Com. Hx. Service. Studio. Attendance. Impl. AttendanceServiceImpl. List (AttendanceServiceImpl. Java: 33)
Com. Hx. Controller. Studio. Attendance. AttendanceController. AttendanceInfo (AttendanceController. Java: 45)
Sun. Reflect. NativeMethodAccessorImpl. Invoke0 (Native Method)
Sun. Reflect. NativeMethodAccessorImpl. Invoke (Unknown Source)
Sun. Reflect. DelegatingMethodAccessorImpl. Invoke (Unknown Source)
Java. Lang. Reflect. Method. Invoke (Unknown Source)
Org. Springframework. Web. Method. Support. InvocableHandlerMethod. DoInvoke (InvocableHandlerMethod. Java: 221)
Org. Springframework. Web. Method. Support. InvocableHandlerMethod. InvokeForRequest (InvocableHandlerMethod. Java: 137)
Org. Springframework. Web. Servlet. MVC) method. The annotation. ServletInvocableHandlerMethod. InvokeAndHandle (ServletInvocableHandlerMethod. Java: 110)
Org. Springframework. Web. Servlet. MVC) method. The annotation. RequestMappingHandlerAdapter. InvokeHandleMethod (RequestMappingHandlerAdapter. Java: 776)
Org. Springframework. Web. Servlet. MVC) method. The annotation. RequestMappingHandlerAdapter. HandleInternal (RequestMappingHandlerAdapter. Java: 705)
Org. Springframework. Web. Servlet. MVC. Method. AbstractHandlerMethodAdapter. Handle (AbstractHandlerMethodAdapter. Java: 85)
Org. Springframework. Web. Servlet. DispatcherServlet. DoDispatch (DispatcherServlet. Java: 959)
Org. Springframework. Web. Servlet. DispatcherServlet. DoService (DispatcherServlet. Java: 893)
Org. Springframework. Web. Servlet. FrameworkServlet. The processRequest (FrameworkServlet. Java: 967)
Org. Springframework. Web. Servlet. FrameworkServlet. DoGet (FrameworkServlet. Java: 858)
Javax.mail. Servlet. HTTP. HttpServlet. Service (HttpServlet. Java: 624)
Org. Springframework. Web. Servlet. FrameworkServlet. Service (843) FrameworkServlet. Java:
Javax.mail. Servlet. HTTP. HttpServlet. Service (HttpServlet. Java: 731)
Org, apache tomcat, websocket server. WsFilter. DoFilter (WsFilter. Java: 52)
Org. Springframework. Web. Filter. CharacterEncodingFilter. DoFilterInternal (CharacterEncodingFilter. Java: 85)
Org. Springframework. Web. Filter. OncePerRequestFilter. DoFilter (OncePerRequestFilter. Java: 107)
Younger brother also know where is wrong, because watching
query. AddCriteria (new Criteria (" attendanceTime "). Gte (startTime));or gaze away
query. AddCriteria (new Criteria (" attendanceTime ".) lt (endTime));can normal query, just don't know what to write, and tied the younger brother to see ~ everyone
CodePudding user response:
Use the and () operation, the Internet a lot of solutions,CodePudding user response:
You can't continue to add this object contains attendanceTime criteria, can increase lt operating behind the object, such as can change to like me this example:If (queryParams. GetStartDate ()!=null | | queryParams. GetEndDate ()!=null) {
If (queryParams. GetStartDate ()!=null & amp; & QueryParams. GetEndDate ()==null) {
Query. AddCriteria (Criteria. The where (" createTimeStamp "). The gte (queryParams. GetStartDate () getTime ()));
} else if (queryParams. GetEndDate ()!=null & amp; & QueryParams. GetStartDate ()==null) {
Query. AddCriteria (Criteria. The where (" createTimeStamp "). The lte (queryParams. GetEndDate () getTime ()));
} else {
Query. AddCriteria (Criteria. The where (" createTimeStamp "). The gte (queryParams. GetStartDate () getTime ()). The lte (queryParams. GetEndDate () getTime ()));
}
}