• date 类型 后端xml中查询非空判断错误


    HTTP Status 500 - Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

     

    type Exception report

    message Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

    description The server encountered an internal error that prevented it from fulfilling this request.

    exception

    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
    ### Error querying database.  Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String
    ### Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
    	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
    	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    

    root cause

    org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
    ### Error querying database.  Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String
    ### Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Date and java.lang.String
    	org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:92)
    	org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)
    	com.sun.proxy.$Proxy18.selectList(Unknown Source)
    	org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:223)
    	org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147)
    	org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)
    	org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:144)
    	org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)
    	com.sun.proxy.$Proxy24.queryAllLogInfo(Unknown Source)
    	com.hbue.sys.service.impl.LogInfoServiceImpl.queryAllLogInfo(LogInfoServiceImpl.java:44)
    	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	java.lang.reflect.Method.invoke(Method.java:498)
    	org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
    	org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    	org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    	org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
    	org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    	org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    	org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    	com.sun.proxy.$Proxy25.queryAllLogInfo(Unknown Source)
    	com.hbue.sys.controller.LogInfoController.loadAllLogInfo(LogInfoController.java:34)
    	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	java.lang.reflect.Method.invoke(Method.java:498)
    	org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
    	org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
    	org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
    	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
    	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
    	org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
    	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    <if test="startTime!=null and startTime!=''">
            and logintime <![CDATA[>=]]> #{startTime}
          </if>
          <if test="endTime!=null and endTime!=''">
            and logintime <![CDATA[<=]]> #{endTime}
          </if>
    

      

    原因:这是因为原因是mybatis 中对于时间参数进行比较时的一个bug. 如果拿传入的时间类型参数与空字符串''进行对比判断则会引发异常. 所以在上面的代码中去掉空字符串判断, 只保留非空判断就正常了。

    解决办法:去掉!=''

    <if test="startTime!=null ">
    and logintime <![CDATA[>=]]> #{startTime}
    </if>
    <if test="endTime!=null ">
    and logintime <![CDATA[<=]]> #{endTime}
    </if>
  • 相关阅读:
    使用jaxb用xsd生成java类
    EMF保存CDATA
    windows builder里面的可伸缩面板
    使用eclipse open type对话框
    eclipse中toolbar位置的系统URI
    bzoj 4414 数量积 结论题
    bzoj 4402 Claris的剑 组合数学
    bzoj 4206 最大团 几何+lis
    bzoj 3676 [Apio2014]回文串 回文自动机
    bzoj 3670 [Noi2014]动物园 kmp
  • 原文地址:https://www.cnblogs.com/YoungSone/p/14415710.html
Copyright © 2020-2023  润新知