Mybatis找不到参数错误:There is no getter for property named 'categoryId' in 'class java.lang.Integer'。
2015-02-12 13:38
936 查看
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,或者对象。
错误
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 'categoryId' in 'class java.lang.Integer'。
- Mybatis 对单独传入参数string进行判断时报There is no getter for property named '**' in 'class java.lang.String解决办法
- 错误解决:There is no getter for property named 'id' in class 'java.lang.String'
- mybatis加Spring项目: 解决There is no getter for property named '***' in 'class java.lang.String'问题
- mybaits错误解决:There is no getter for property named 'id' in class 'java.lang.Long'
- Mybatis-There is no getter for property named 'tj' in 'class java.lang.String'
- There is no getter for property named 'xxxx' in 'class java.lang.Integer
- mybatis报错 There is no getter for property named 'xx' in 'class java.lang.String
- MyBatis There is no getter for property named 'xxx' in 'class java.lang.String'
- mybatis There is no getter for property named 'xx' in 'class java.lang.String
- mybatis There is no getter for property named 'xx' in 'class java.lang.String
- org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'funcSetId' in 'class java.lang.Integer'
- Mybatis-There is no getter for property named 'id' in 'class java.lang.String'
- There is no getter for property named 'num' in 'class java.lang.String'。
- MyBatisSystemException There is no getter for property named 'id' in 'class java.lang.String'
- There is no READABLE property named 'id' in class 'java.lang.Integer'
- MyBatis错误:There is no getter for property named 'paramSql' in 'class java.lang.String'
- Mybatis-There is no getter for property named 'id' in 'class java.lang.String'
- mybaits的There is no getter for property named 'id' in 'class java.lang.Integer异常