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. 使用IPV6

    使用IPV6 知道IPV6已经很久了,但是一直没有使用过. 我使用的IPV4网络一般是 内网-->外网-->互联网,IPV6也不外乎这样,但是对IPV6而言,必须有它的"世界&q ...

  2. Python编写Appium测试用例(1)

    有段时间没有使用python编写测试用例了,很长时间以来,感觉appium这个测试工具确实不错,今天又重新拿起来,分享一下自己学习的一些用例,欢迎大家一起交流.学习! 1.登录客户端 #coding= ...

  3. sampleviewer add menu item error 'assert'

    可以跟踪到 mfc提供的源代码内部,(注:如果打开了mfc源代码,设置了断点,但是跟不进去,那就需要更新PDB文件,具体网上搜)打开 wincore.cpp文件(D:\Program Files\Mi ...

  4. html doctype作用

    简单介绍下html页面中DOCTYPE声明的作用: <!doctype html>告诉浏览器是使用标准模式还是怪异模式渲染页面. 1.为html页面添加了doctype,则浏览器在stan ...

  5. (转)iptables详细教程:基础、架构、清空规则、追加规则、应用实例

    转自:http://lesca.me/archives/iptables-tutorial-structures-configuratios-examples.html iptables防火墙可以用于 ...

  6. 像Bootstrap一样比较热门的前端框架有哪些

    像Bootstrap一样比较热门的前端框架有哪些 一.总结 一句话总结:框架大同小异,可以多去各自官网看看效果(比较一下各自的不同点(也就是提供的不同的功能)),然后根据需求选择用哪个.我觉得boot ...

  7. CYPRESS USB芯片win10驱动

    The ZIP file attached with this knowledge base article contains the CyUSB3.inf and CyUSB3.sys files ...

  8. Java与IOS日期格式

    //JAVA日期格式 Date date = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM- ...

  9. [RxJS] Connection operator: multicast and connect

    We have seen how Subjects are useful for sharing an execution of an RxJS observable to multiple obse ...

  10. Hibernate与代理模式

    代理模式:当须要调用某个对象的时候.不须要关心拿到的是不是一定是这个对象,它须要的是,我拿到的这个对象能够完毕我想要让它完毕的任务就可以,也就是说.这时调用方能够拿到一个代理的一个对象,这个对象能够调 ...