Mybatis找不到参数错误:There is no getter for property named 'categoryId' in 'class java.lang.Integer'。
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'。的更多相关文章
- 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 ...
- 当传入数据只有一个时mybatis中<if>判断会出现There is no getter for property named 'subjectId' in 'class java.lang.Intege
用"_parameter"代替当前参数 正确: <select id="selectSubjectByPId" parameterType="j ...
- MyBatis if test 传入一个数字进行比较报错 There is no getter for property named 'userState' in 'class java.lang.Integer'
在写MyBatis映射文件中,我要传入一个 int 类型的参数,在映射文件中用 'test' 中进行比较,我花了很长时间百度,发现都是不靠谱的方法,有把数字在比较时转成字符串用 equals 比较的. ...
- 关于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' ...
- 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 ...
- 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进行传参的时候 ...
- mybatis问题: There is no getter for property named 'equipmentId' in 'class java.lang.String'
本文来源于翁舒航的博客,点击即可跳转原文观看!!!(被转载或者拷贝走的内容可能缺失图片.视频等原文的内容) 若网站将链接屏蔽,可直接拷贝原文链接到地址栏跳转观看,原文链接:https://www.cn ...
- 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 ...
- 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 ...
随机推荐
- 16、cgminer学习之:popen函数和system函数详解(执行系统命令)
1.popen函数我们先用man指令查一下popen函数: 函数说明: (1)popen()会调用fork()产生子进程,然后从子进程中调用/bin/sh -c来执行参数command的指令. (2) ...
- [python]bug和debug
bug:代码中存在的语法或者逻辑问题 debug:自查和解决代码中的问题 (coding五分钟,debug两小时) 一.出现bug原因的四大类型 1.粗心 1)错误案例 上面这个错误就是因为 if语句 ...
- 【习题 6-9 UVA - 127】"Accordian" Patience
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 链表模拟即可. 1pile不能加s... [代码] #include <bits/stdc++.h> using nam ...
- Java Web学习总结(5)——HttpServletResponse对象详解
一.HttpServletResponse常见应用--生成验证码 1.1.生成随机图片用作验证码 生成图片主要用到了一个BufferedImage类, 生成随机图片范例: package gacl.r ...
- Maven学习总结(15)——Maven 项目中pom.xml详解
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2 ...
- COdeVS——T 1082 线段树练习 3 (分块练习)
http://codevs.cn/problem/1082/ 时间限制: 3 s 空间限制: 128000 KB 题目等级 : 大师 Master 题解 题目描述 Descriptio ...
- ORACLE 11G R2 DG_BROKER 之SWITCH OVER
官网:http://docs.oracle.com/cd/B12037_01/server.101/b10822/cli.htm 这个是有必要看一下. 注意本人已经完毕一次SWITCHOVER 所 ...
- Oracle10g中阻塞锁查询更简单
http://blog.itpub.net/195110/viewspace-677572/ http://blog.sina.com.cn/s/blog_636415010100khcl.html
- 定制表格头, 学习Core Graphic 的第二部分, 阴影与玻璃效果.
//定制表格头, 学习Core Graphic 的第二部分, 阴影与玻璃效果. https://github.com/comcuter/testsnippets/commit/e96f62d115ef ...
- [AngularJS] Interpolation fail in IE 11
When you occured this problem, check few things: For the input field, use // Use ng-attr-placeholder ...