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. Android中实现整个视图切换的左右滑动效果

    Android中提供了一个Gallary,可以实现图片或者文本的左右滑动效果. 如何让整个视图都能实现左右滑动,达到类似于Gallary的效果呢?可以直接用一个开源的ViewFlow来实现.   项目 ...

  2. 1.1 Introduction中 Consumers官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Consumers 消费者(Consumers) Consumers label t ...

  3. python2与python3的不同

    1.源码: python2的源码混乱.冗余.重复,非常不规范 python3的源码经过整合,优美.清晰.简单 2.编码: python2的默认编码是ASCII码,不能识别中文,需要在行首添加# -*- ...

  4. Docker---(2)为什么要用Docker

    原文:Docker---(2)为什么要用Docker 版权声明:欢迎转载,请标明出处,如有问题,欢迎指正!谢谢!微信:w1186355422 https://blog.csdn.net/weixin_ ...

  5. Project Euler 501 Eight Divisors (数论)

    题目链接: https://projecteuler.net/problem=501 题意: \(f(n)\) be the count of numbers not exceeding \(n\) ...

  6. android String 类型转换成UTF-8格式

    在android开发中,有时候会遇到汉字乱码的问题,在这个时候,吧String串加一个编码格式转换,转换成UTF-8的格式就可以了 public static String toUtf8(String ...

  7. GCJ 2008 Round 1A Minimum Scalar Product

    https://code.google.com/codejam/contest/32016/dashboard 题目大意: GCJ(google code jam)上的水题.下周二有比赛,来熟悉熟悉. ...

  8. postman--下载及使用入门

    安装 本文只是基于 Chrome 浏览器的扩展插件来进行的安装,并非单独应用程序. 首先,你要台电脑,其次,安装有 Chrome 浏览器,那你接着往下看吧. 1. 官网安装(别看) 打开官网,http ...

  9. Redis学习笔记--Hash(五)

    Redis的数据是通过key-value的方式存储的,对于value的数据类型有字符串.Hash.list.set.sortedSet在redis命令语句中,语句是忽略大小写的,但是key是不可以忽略 ...

  10. 三个Bootstrap免费字体和图标库

    前言:Bootstrap 简洁.直观.强悍.移动设备优先的前端开发框架,让web开发更迅速.简单 ,深入了解 Bootstrap 底层结构的关键部分,包括我们让 web 开发变得更好.更快, 组件无数 ...