记一次操蛋的:Could not find parameter map java.lang.Long

学着写淘淘商场的项目,刚开始的搭建轻轻松松,按照教程来很顺利,也可以轻松运行出来结果。

但是今天(2018-11-11)却遇到一个非常奇葩的事,代码如下

<resultMap  type="com.pp.taotao.model.ItemCat" >
    <constructor >
      <idArg column="id" jdbcType="BIGINT" javaType="java.lang.Long" />
      <arg column="parent_id" jdbcType="BIGINT" javaType="java.lang.Long" />
      <arg column="name" jdbcType="VARCHAR" javaType="java.lang.String" />
      <arg column="status" jdbcType="INTEGER" javaType="java.lang.Integer" />
      <arg column="sort_order" jdbcType="INTEGER" javaType="java.lang.Integer" />
      <arg column="is_parent" jdbcType="BIT" javaType="java.lang.Boolean" />
      <arg column="created" jdbcType="TIMESTAMP" javaType="java.util.Date" />
      <arg column="updated" jdbcType="TIMESTAMP" javaType="java.util.Date" />
    </constructor>
  </resultMap>
  <sql  >
    id, parent_id, name, status, sort_order, is_parent, created, updated
  </sql>
  
  <!--根据parent_id查询数据-->
  <select  resultMap="BaseResultMap" parameterMap="java.lang.Long">
    select
    <include ref />
    from tb_item_cat
    where parent_id = #{id,jdbcType=BIGINT}
  </select>

这是一个Mapper文件,有Mybatis逆向工程生成的,下面这段代码是我自己写的,根据传入的id查询出对应的数据;

<!--根据parent_id查询数据-->
  <select  resultMap="BaseResultMap" parameterMap="java.lang.Long">
    select
    <include ref />
    from tb_item_cat
    where parent_id = #{id,jdbcType=BIGINT}
  </select>

然后执行程序报了如下错误:org.apache.ibatis.builder.IncompleteElementException: Could not find parameter map java.lang.Long

瞬间一脸懵逼,MMP,前几天还好好的,怎么突然报错了。。。。。。

跟踪错误,跑到了我之前可以完美执行的代码下,我擦,什么鬼情况。。。。倒腾了一晚上,没结果。。。

无限百度查,还是迷迷糊糊,那就随便试被,最后根据该微博https://blog.csdn.net/sunnyzyq/article/details/71157962搞定了,感觉像是瞎猫碰上死耗子,呵呵哒。

错误原因是Mybatis配置文件语句有问题,原语句为:

<!--根据parent_id查询数据-->
  <select  resultMap="BaseResultMap" parameterMap="java.lang.Long">
    select
    <include ref />
    from tb_item_cat
    where parent_id = #{id,jdbcType=BIGINT}
  </select>

原因:java.lang.Long类型不能用parameterMap修饰,改为parameterType即可,故修改后的正确语句为:

<!--根据parent_id查询数据-->
  <select  resultMap="BaseResultMap" parameterType="java.lang.Long">
    select
    <include ref />
    from tb_item_cat
    where parent_id = #{id,jdbcType=BIGINT}
  </select>

这这这~~~~~不敢相信啊,就是Map和Type之差,真的是瞬间一万只草泥马在蹦腾啊。。。。。

哎,写代码还是要非常非常细心的,加油加油,seven!!!!!!