美文网首页java学习笔记
Mybatis查询报错:There is no getter f

Mybatis查询报错:There is no getter f

作者: 东方欲晓_莫道君行早 | 来源:发表于2019-03-14 16:38 被阅读0次

    问题:
    执行查询时报错:There is no getter for property named '*' in 'class java.lang.String
    原因:
    传过去的参数为识别。本例为

    public interface TestMapper{
        List<Base> findAllBase(String search);
    }
    
    <select id="findAllBase" resultType="*.Base" parameterType="String">
            select id,name from t_base
            where 1=1
            <if test="search != null and search != ''">
                AND name LIKE CONCAT('%',#{search },'%')
            </if>
            order by id
    </select>
    

    解决方法:
    1、在mapper接口增加参数设置,如下:

    public interface TestMapper{
        List<Base> findAllBase(@Param(value="search") String search);
    }
    

    2、将具体报错的变量名更换为_parameter,如下:

    <select id="findAllBase" resultType="*.Base" parameterType="String">
            select id,name from t_base
            where 1=1
            <if test="_parameter!= null and _parameter!= ''">
                AND name LIKE CONCAT('%',#{search },'%')
            </if>
            order by id
    </select>
    

    相关文章

      网友评论

        本文标题:Mybatis查询报错:There is no getter f

        本文链接:https://www.haomeiwen.com/subject/mukcmqtx.html