Mybatis找不到参数错误:There is no getter for property named 'categoryId' in 'class java.lang.Integer'。

错误
List<Post> listPage(Integer categoryId);
在测试时报错:There is no getter for property named 'categoryId' in 'class java.lang.Integer'

问题分析:Mybatis默认采用ONGL解析参数,所以会自动采用对象树的形式取string.value值,引起报错。
 解决方法:  List<Post> listPage(@Param("categoryId")Integer categoryId); 说明参数值。
 
 sql语句
<select id="listPage" resultMap="PostResultMap">
select id,title,summary,create_time from p2p_post
where status=0 
<if test="categoryId != null">
 and category_id=#{categoryId}
</if>
order by id
desc
</select>

最让人郁闷的是,以前在只有1个参数的时候,都是不用@Param注解的,一般只有在多个参数的时候,才需要用。
 为什么这次,只有1个参数,也必须用@Params注解呢?
 -----------------------
 第2天早上,问了下boss,感觉还是有道理的。
 
 正解一:
 @Select("select * from ..")
 List<Post> listPage(Integer categoryId);
 
 正解二:
  List<Post> listPage(@Param("categoryId")Integer categoryId);
  <select>..</select>
  
 正解三:
   List<Post> listPage(Integer categoryId);
  <select id="listPage" parameterType="java.lang.Integer" resultMap="PostResultMap">
  
  </select>
 
 昨天遇到的那个问题,问题关键就是:xml文件中的select映射语句,默认参数类型是map,从map里取属性,所以总是找不到。
 或者是当作对象类型吧。
 因此,用@Param注解或手动指定参数类型。
 
 理论上是这样,没有去一一校验。
 
 另外需要说明,多个参数,必须使用@Param,或者用Map,或者对象。

Mybatis找不到参数错误:There is no getter for property named 'categoryId' in 'class java.lang.Integer'。的更多相关文章

  1. MyBatis查询传一个参数时报错:There is no getter for property named 'sleevetype' in 'class java.lang.Integer

    用MyBatis进行查询,传入参数只有一个时(非Map)如int,报错 There is no getter for property named 'sleevetype' in 'class jav ...

  2. 当传入数据只有一个时mybatis中<if>判断会出现There is no getter for property named 'subjectId' in 'class java.lang.Intege

    用"_parameter"代替当前参数 正确: <select id="selectSubjectByPId" parameterType="j ...

  3. MyBatis if test 传入一个数字进行比较报错 There is no getter for property named 'userState' in 'class java.lang.Integer'

    在写MyBatis映射文件中,我要传入一个 int 类型的参数,在映射文件中用 'test' 中进行比较,我花了很长时间百度,发现都是不靠谱的方法,有把数字在比较时转成字符串用 equals 比较的. ...

  4. 关于mybtis 使用过程中发生There is no getter for property named 'id' in class 'java.lang.String' 错误

    今天在修改一个关于mybtis语句时,偶然发现的一个错误  There is no getter for property named 'id' in class 'java.lang.String' ...

  5. mybatis There is no getter for property named 'xx' in 'class java.lang.String

    转载自://http://www.cnblogs.com/anee/p/3324140.html 用mybatis查询时,传入一个字符串传参数,且进行判断时,会报 There is no getter ...

  6. mybatis 异常 There is no getter for property named 'bizId' in 'class java.lang.Long'

    mybatis 异常 There is no getter for property named 'bizId' in 'class java.lang.Long' 当使用mybatis进行传参的时候 ...

  7. mybatis问题: There is no getter for property named 'equipmentId' in 'class java.lang.String'

    本文来源于翁舒航的博客,点击即可跳转原文观看!!!(被转载或者拷贝走的内容可能缺失图片.视频等原文的内容) 若网站将链接屏蔽,可直接拷贝原文链接到地址栏跳转观看,原文链接:https://www.cn ...

  8. Mybatis笔记四:nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'id' in 'class java.lang.String'

    错误异常:nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for pr ...

  9. Mybatis问题:There is no getter for property named 'unitId' in 'class java.lang.String'

    Mybatis遇到的问题 问题: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.re ...

随机推荐

  1. [Angular] Custom directive Form validator

    Create a directive to check no special characters allowed: import {Directive, forwardRef} from '@ang ...

  2. word2vec源代码解析之word2vec.c

    word2vec源代码解析之word2vec.c 近期研究了一下google的开源项目word2vector,http://code.google.com/p/word2vec/. 事实上这玩意算是神 ...

  3. elasticsearch 源码概述

    从功能上说,可以分为两部分,分布式功能和数据功能.分布式功能主要是节点集群及集群附属功能如restful借口.集群性能检测功能等,数据功能主要是索引和搜索.代码上这些功能并不是完全独立,而是由相互交叉 ...

  4. jni和C++通信中文乱码的问题

    转自 http://www.cnblogs.com/bluesky4485/archive/2011/12/13/2285802.html 首先,需要明确几个关于编码的基本概念: java内部是使用的 ...

  5. Android新控件RecyclerView剖析

    传智·没羽箭(传智播客北京校区Java学院高级讲师) 个人简单介绍:APKBUS专家之中的一个,黑马技术沙龙会长,在移动领域有多年的实际开发和研究经验.精通HTML5.Oracle.J2EE .Jav ...

  6. Hadoop笔记(一)

    1.大数据的概述 大数据:巨量数据.海量数据,首先在数据的量上达到一定的规模,首先是人或者计算机在不合理时间内是不能够实现的数据量. 2.特点:数据量比较大,数据类型多样化.处理速度问题 3.大数据平 ...

  7. volatile关键字深入理解

    前言: 这个关键字的重点就三个字,就是可见性.但是面试的时候,你说出可见性三个字,基本上满分100的话,最多只能得到20分.剩下的那80分,就要靠你用硬功夫去获得了. 所谓的硬功夫,其实就是要整明白, ...

  8. fatfs的设置

    官方网址:file:///E:/%E5%8D%95%E7%89%87%E6%9C%BA/FATFS/ff13a/documents/doc/config.html 关于多个文件同时打开的配置::在ff ...

  9. LA 3887 - Slim Span 枚举+MST

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  10. 10.14 android输入系统_多点触摸驱动测试及Reader线程、InputStage分析

    21. 多点触摸_电容屏驱动程序_实践_tiny4412 tiny4412触摸屏: 分辨率为800 x 480http://wiki.friendlyarm.com/wiki/index.php/LC ...