Mybatis 出现异常Error querying database. Cause: java.lang.NullPointerException

今天在自己写一个关于springboot的小Demo时,一直出现Error querying database.  Cause: java.lang.NullPointerException的异常,前前后后仔仔细细检查也没找到哪里会出现空指针的问题,在网上寻找答案又不是所描述的问题,然后就自己琢磨,最后尝试修改了下图中jdbcType为javaType,发现接口是调通了。

 

-------------------------但是,但是,但是,(重要的事情说三遍)------------------------

 

正在窃窃自喜的时候发现返回的数据是这样的。

MockHttpServletResponse:
           Status = 200
    Error message = null
          Headers = {Content-Type=[application/json;charset=UTF-8]}
     Content type = application/json;charset=UTF-8
             Body = {"message":null,"result":[[{"date":"1300.00","money":1300.00},{"date":"200.00","money":200.00},{"date":"20000.00","money":20000.00},{"date":"100.00","money":100.00},{"date":"20447.00","money":20447.00},{"date":"200.00","money":200.00},{"date":"56977.00","money":56977.00},{"date":"7973.00","money":7973.00},{"date":"48900.00","money":48900.00},{"date":"33425.00","money":33425.00},{"date":"84167.00","money":84167.00},{"date":"9100.00","money":9100.00},{"date":"46700.00","money":46700.00},{"date":"47300.00","money":47300.00},{"date":"25370.00","money":25370.00},{"date":"31000.00","money":31000.00},{"date":"30100.00","money":30100.00},{"date":"10300.00","money":10300.00},{"date":"53600.00","money":53600.00},{"date":"84400.00","money":84400.00},{"date":"9700.00","money":9700.00},{"date":"47960.00","money":47960.00},{"date":"400.00","money":400.00},{"date":"20205.00","money":20205.00},{"date":"22536.00","money":22536.00},{"date":"62660.00","money":62660.00},{"date":"32700.00","money":32700.00},{"date":"18335.00","money":18335.00},{"date":"126082.00","money":126082.00},{"date":"22300.00","money":22300.00},{"date":"108500.00","money":108500.00},{"date":"224200.00","money":224200.00},{"date":"203400.00","money":203400.00},{"date":"164649.00","money":164649.00},{"date":"135010.00","money":135010.00}]],"code":200}
    Forwarded URL = null
   Redirected URL = null
          Cookies = []
--------返回的json = {"message":null,"result":[[{"date":"1300.00","money":1300.00},{"date":"200.00","money":200.00},{"date":"20000.00","money":20000.00},{"date":"100.00","money":100.00},{"date":"20447.00","money":20447.00},{"date":"200.00","money":200.00},{"date":"56977.00","money":56977.00},{"date":"7973.00","money":7973.00},{"date":"48900.00","money":48900.00},{"date":"33425.00","money":33425.00},{"date":"84167.00","money":84167.00},{"date":"9100.00","money":9100.00},{"date":"46700.00","money":46700.00},{"date":"47300.00","money":47300.00},{"date":"25370.00","money":25370.00},{"date":"31000.00","money":31000.00},{"date":"30100.00","money":30100.00},{"date":"10300.00","money":10300.00},{"date":"53600.00","money":53600.00},{"date":"84400.00","money":84400.00},{"date":"9700.00","money":9700.00},{"date":"47960.00","money":47960.00},{"date":"400.00","money":400.00},{"date":"20205.00","money":20205.00},{"date":"22536.00","money":22536.00},{"date":"62660.00","money":62660.00},{"date":"32700.00","money":32700.00},{"date":"18335.00","money":18335.00},{"date":"126082.00","money":126082.00},{"date":"22300.00","money":22300.00},{"date":"108500.00","money":108500.00},{"date":"224200.00","money":224200.00},{"date":"203400.00","money":203400.00},{"date":"164649.00","money":164649.00},{"date":"135010.00","money":135010.00}]],"code":200}

WTF,怎么分明两个字段,怎么两个字段都映射出金额的数据的?最后的最后,发现问题了,

Mybatis 出现异常Error querying database. Cause: java.lang.NullPointerException_第1张图片

原来是这个注解搞的鬼,在没有xml映射实体时,我们可以用这个注解灵活映射,但是在有这个注解的时候,他不再执行xml实体文件了,所以解决办法:用此注解就不需要xml映射实体了,或者在有xml映射实体的情况下,去除@Mapper注解。其实和jdbcType和JavaType没关系的。

你可能感兴趣的:(java,mybatis,springboot)