使用createdOn过滤器过滤结果

时间:2014-08-29 06:17:14

标签: java hibernate

if(param.startsWith("FILTER_PARAM_")) {
    String value = WebUtils.deriveParam(param, request.getParameterMap());
    String field =  param.split("_")[2];
    if("createdOn".equalsIgnoreCase(field)){
        try {
            Date filterDate = ConversionUtils.convertFromString(value);
            SimpleDateFormat timeFormat = new SimpleDateFormat("dd-MMM-yy HH:mm:ss.SSSSSSSSS aa");
            value = timeFormat.format(filterDate);
            params.put("createdDate", value);
        }
        catch(Exception exception) {
            // TODO Empty results
        }
    } else {
        params.put(field, value);
    }
}

public static String dateFormat = "MM/dd/yyyy";

public static Date convertFromString(String dateString) throws Exception {
    if (StringUtils.isNotEmpty(dateString)) {
        DateFormat formatter = new SimpleDateFormat(dateFormat);
        formatter.setLenient(false);
        return formatter.parse(dateString);
    }
    return null;
}

在数据库中,该列是' CreatedDate' : TIMESTAMP(6),例如25-AUG-14 11.26.16.369000000 AM

在用户界面上,用户将日期字符串设为" 08/25/2014 "。

我必须使用给定的日期过滤列。 试过上面的代码,它给出了以下例外:

2014-09-11 12:21:14,749 DEBUG [http-8081-29] c.h.u.e.DefaultExceptionLoggingHandler [AbstractHandlerExceptionResolver.java:132] Resolving exception from handler [public com.hcentive.utils.search.datatable.model.DatatableSearchResponse com.hcentive.agent.web.controller.CoverPageTemplateController.getTemplatesList(org.springframework.ui.Model,javax.servlet.http.HttpServletRequest) throws java.lang.Exception]: com.hcentive.utils.exception.HCException: GENERIC_ERROR:Unknown Error has happened
2014-09-11 12:21:14,752 ERROR [http-8081-29] c.h.u.e.DefaultExceptionLoggingHandler [DefaultExceptionLoggingHandler.java:64] Some unknown error has happened, please try again later.{Actual Message- GENERIC_ERROR:Unknown Error has happened}
com.hcentive.utils.exception.HCException: GENERIC_ERROR:Unknown Error has happened
    at com.hcentive.utils.search.service.CriteriaBasedSearchService.search(CriteriaBasedSearchService.java:49) ~[utils-1.5.jar:na]
    at com.hcentive.utils.search.service.CriteriaBasedSearchService$$FastClassByCGLIB$$3afe362.invoke(<generated>) ~[cglib-2.2.jar:na]
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191) ~[cglib-2.2.jar:na]
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689) ~[spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) ~[spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) ~[spring-tx-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622) ~[spring-aop-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at com.hcentive.utils.search.service.CriteriaBasedSearchService$$EnhancerByCGLIB$$a6c400e4.search(<generated>) ~[cglib-2.2.jar:na]
    at com.hcentive.utils.search.web.QuerySearchController.search(QuerySearchController.java:21) ~[utils-1.5.jar:na]
    at com.hcentive.utils.search.datatable.web.DatatableSearchController.search(DatatableSearchController.java:42) ~[utils-1.5.jar:na]
    at com.hcentive.utils.search.datatable.web.DatatableSearchController.search(DatatableSearchController.java:35) ~[utils-1.5.jar:na]
    at com.hcentive.agent.web.controller.CoverPageTemplateController.getTemplatesList(CoverPageTemplateController.java:150) ~[agent-web-hix-1.5.jar:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_22]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.6.0_22]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.6.0_22]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.6.0_22]
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213) ~[spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126) ~[spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96) ~[spring-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617) ~[spring-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578) ~[spring-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) ~[spring-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) [spring-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) [spring-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) [spring-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) [spring-webmvc-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) [servlet-api.jar:na]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) [servlet-api.jar:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) [catalina.jar:6.0.33]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.33]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) [spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:6.0.33]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.33]
    at com.hcentive.agent.web.filter.AssistorFilter.doFilterInternal(AssistorFilter.java:131) [agent-web-hix-1.5.jar:na]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:6.0.33]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.33]
    at com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129) [sitemesh-2.4.2.jar:na]
    at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77) [sitemesh-2.4.2.jar:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:6.0.33]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.33]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at com.hcentive.utils.security.filter.PasswordChangeFilter.doFilterInternal(PasswordChangeFilter.java:87) [utils-1.5.jar:na]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter.doFilter(AbstractPreAuthenticatedProcessingFilter.java:88) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at com.hcentive.co.common.web.security.filter.CGIRequestHeaderAuthenticationFilter.doFilter(CGIRequestHeaderAuthenticationFilter.java:135) [co-common-1.0-Snapshot.jar:na]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) [spring-security-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) [spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) [spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:6.0.33]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.33]
    at com.hcentive.utils.web.xss.filter.XSSFilter.doFilter(XSSFilter.java:37) [utils-1.5.jar:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:6.0.33]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.33]
    at com.hcentive.utils.web.xss.filter.LocaleConfigurerFilter.doFilterInternal(LocaleConfigurerFilter.java:40) [utils-1.5.jar:na]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:6.0.33]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.33]
    at com.hcentive.utils.web.flash.FlashMapFilter.doFilterInternal(FlashMapFilter.java:70) [utils-1.5.jar:na]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:6.0.33]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.33]
    at com.hcentive.utils.web.cookie.CookieEnabledFilter.doFilterInternal(CookieEnabledFilter.java:55) [utils-1.5.jar:na]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:6.0.33]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.33]
    at com.hcentive.utils.web.clickjack.ClickJackFilter.doFilterInternal(ClickJackFilter.java:27) [utils-1.5.jar:na]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:6.0.33]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.33]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) [spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [spring-web-3.1.2.RELEASE.jar:3.1.2.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:6.0.33]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:6.0.33]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) [catalina.jar:6.0.33]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [catalina.jar:6.0.33]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [catalina.jar:6.0.33]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [catalina.jar:6.0.33]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [catalina.jar:6.0.33]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291) [catalina.jar:6.0.33]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) [tomcat-coyote.jar:6.0.33]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602) [tomcat-coyote.jar:6.0.33]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) [tomcat-coyote.jar:6.0.33]
    at java.lang.Thread.run(Unknown Source) [na:1.6.0_22]
Caused by: java.text.ParseException: Unparseable date: "11-Sep-14 00:00:00.000000000 AM"
    at java.text.DateFormat.parse(Unknown Source) ~[na:1.6.0_22]
    at com.hcentive.utils.orm.hibernate.HibernateCriteriaUtils.getSubCriterion(HibernateCriteriaUtils.java:323) ~[utils-1.5.jar:na]
    at com.hcentive.utils.orm.hibernate.HibernateCriteriaUtils.buidCriteria(HibernateCriteriaUtils.java:107) ~[utils-1.5.jar:na]
    at com.hcentive.utils.orm.hibernate.HibernateCriteriaUtils.buildCountCriteria(HibernateCriteriaUtils.java:97) ~[utils-1.5.jar:na]
    at com.hcentive.utils.search.service.CriteriaBasedSearchService.search(CriteriaBasedSearchService.java:38) ~[utils-1.5.jar:na]
    ... 104 common frames omitted

1 个答案:

答案 0 :(得分:0)

崩溃发生在以下一行:

Date filterDate = ConversionUtils.convertFromString(value);

原因是ConversionUtils.convertFromString()中使用的SimpleDateFormatMMMM d, yyyy,而您正在传递25-AUG-14 11.26.16.369000000 AM