ITeye博客

org.apache.ibatis.reflection.ReflectionException: There is no getter for propert

samwalt · 2016-02-22 18:39 · java · 编程语言 · Markdown

在使用mybatis的模糊查询的时候,需要从jsp传入到controller中一个keyword【String】,在mapper.xml中我是这样写的

    <select id="fuzzyFind" resultMap="articleResultMap" parameterType="string">  
        <![cdata[ 
            select * from articles where 1=1 
        ]]>  
        <if test="keyword != null">  
            <![cdata[ and article_title like concat('%','${keyword}','%') ]]>  
        </if>  
    </select>  

然后用junit测试的时候,后台报了org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'keyword' in 'class java.lang.String'这样的一个错误,说keyword这个属性没有getter方法,然而我这个keyword不是javabean,没有必要为其设置getter方法,那怎么办呢?我在网上看到了这样的几种解决方法:

  1. 将string类型换成map类型的,然后将该keyword 放入该map中,不会报错

  2. 在接口中使用@Param(value="xxx") String xxx, 例如:public List fuzzyFind(@Param(value = "keyword") String keyword); 也可以解决问题, 但是我这样写还是出现了同样的错误

  3. 在配置文件中直接将keyword换成_parameter,问题解决。


    <select id="fuzzyFind" resultMap="articleResultMap" parameterType="string">  
        <![cdata[ 
            select * from articles where 1=1 
        ]]>  
        <if test="_parameter != null">  
            <![cdata[ and article_title like concat('%','${_parameter}','%') ]]>  
        </if>  
    </select>  

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。