spring-boot mybatis 查询mysql报错问题

 2018-06-24 17:32:23.171 ERROR 6371 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.NullPointerException
### The error may exist in file [/Users/ww/IdeaProjects/test-Service/test-Search/target/classes/mapping/TestMapper.xml]
### The error may involve com.test.data.mapper.TestMapper.selectByPrimaryKey
### The error occurred while executing a query
### Cause: java.lang.NullPointerException] with root cause

java.lang.NullPointerException: null

我的pom.xml

  <!-- Spring Boot Mybatis-->
      <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
      </dependency>

      <!-- 数据源 -->
      <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid</artifactId>
        <version>1.0.19</version>
      </dependency>
      <!-- MySQL-->
      <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.39</version>
      </dependency>

TestMapper.java代码

     TestConfig selectByPrimaryKey(Long id);

TestMapper.xml

  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select
    <include refid="Base_Column_List" />
    from test_config
    where id = #{id,jdbcType=BIGINT}
  </select>

请各位大神帮忙看一下,几乎所有查询都报这个错误,用了@Param 注释也不行

mapping/TestMapper.xml 、 com.test.data.mapper.TestMapper.selectByPrimaryKey 检查一下 所在包,感觉不在一个包下呢?

搞不好 是没在一个包下, 扫描不到 这个命名空间的 selectByPrimaryKey 方法,也有可能哟。。。

报空指针,你的DAO没有注入成功吧?

17:56:55.520 [main] DEBUG org.mybatis.spring.mapper.ClassPathMapperScanner - Enabling autowire by type for MapperFactoryBean with name 'testMapper'.

图片说明

这里改成 long ,不要自己 定义

parameterType="long"

将id 参数打印出来看一下,应该为 null,至于为什么 就得你自个儿分析咯,这点代码 看不出来,如还不行 可试着 重新build 一下

parameterType="java.lang.Long" 是没有任何问题的, 应该是 传入参数 id值 为null, 断点 跟踪一下。。。