There is no getter for property named 'type' in 'class java.lang.String'

版权声明:转发请标明出处,谢谢! https://blog.csdn.net/Myuhua/article/details/85048193

错误信息:大体意思是说“type”这个参数没有getter

org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'type' in 'class java.lang.String'
	at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:419)
	at org.apache.ibatis.reflection.MetaClass.getGetInvoker(MetaClass.java:164)
	at org.apache.ibatis.reflection.wrapper.BeanWrapper.getBeanProperty(BeanWrapper.java:162)
	at org.apache.ibatis.reflection.wrapper.BeanWrapper.get(BeanWrapper.java:49)
	at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:122)
	at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextMap.get(DynamicContext.java:94)

错误原因:这个错误我一年前就碰到过了,当时事情解决后就没做记录这次又让我碰到了,冤家路窄,这下得好好把它记录一下。我们通过对错误的翻译,我相信多数人都是会看一下自己的实体类里面是不是缺少的type的get方法,结果你发现你有相关的方法(真没写的另说),其实直接原因并不是因为这个,我们来看一下以下mapper中内容:

  <select id="getEnumInfoListByType" parameterType="java.lang.String"
            resultType="com.jd.ecodd.param.concat.client.vo.QueryEnumInfoVo">
        SELECT
        <include refid="baseColumn"/>
        FROM t_tableName
        <where>
            <if test="type!=null and type!=''">
                'type' LIKE CONCAT ('%',#{type},'%')
            </if>
        </where>
    </select>

我们会看到,我们的参数类型String类型,而在mybatis中这种类型有一种固定的方法就是将要传入的string类型参数用_parameter来代替。

解决方法:

  <select id="getEnumInfoListByType" parameterType="java.lang.String"
            resultType="com.jd.ecodd.param.concat.client.vo.QueryEnumInfoVo">
        SELECT
        <include refid="baseColumn"/>
        FROM t_tableName
         <where>
            <if test="_parameter!=null and _parameter!=''">
                type LIKE CONCAT ('%',#{_parameter},'%')
            </if>
        </where>
    </select>

猜你喜欢

转载自blog.csdn.net/Myuhua/article/details/85048193
今日推荐