Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'zoneId' in 'class java.lang.String'


本文為博主原創,未經允許不得而轉載:

      異常展示:

      dao層定義的接口為:

public int getClientTotal();

在mybatis中的sql為:

<select id="getClientTotal" parameterType="String" resultType="Integer">
        SELECT COUNT(*) AS oldNum FROM tbl__client_info 
        <where>
            <if test="zoneId!=null and !&quot;&quot;.equals(zoneId.trim())">
                and zone1Id = #{zoneId}
            </if>
        </where>
    </select>

在運行的時候控制台報一下異常:

Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'zoneId' in 'class java.lang.String'
    at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:422) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.reflection.MetaClass.getGetInvoker(MetaClass.java:164) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.reflection.wrapper.BeanWrapper.getBeanProperty(BeanWrapper.java:162) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.reflection.wrapper.BeanWrapper.get(BeanWrapper.java:49) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:122) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextMap.get(DynamicContext.java:94) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextAccessor.getProperty(DynamicContext.java:108) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.ognl.OgnlRuntime.getProperty(OgnlRuntime.java:2666) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.ognl.ASTProperty.getValueBody(ASTProperty.java:114) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:258) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.ognl.ASTNotEq.getValueBody(ASTNotEq.java:50) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:258) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.ognl.ASTAnd.getValueBody(ASTAnd.java:61) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:258) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:467) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:431) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:44) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:32) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.scripting.xmltags.IfSqlNode.apply(IfSqlNode.java:34) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:33) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.scripting.xmltags.TrimSqlNode.apply(TrimSqlNode.java:55) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:33) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:41) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:292) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141) ~[mybatis-3.4.2.jar:3.4.2]
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77) ~[mybatis-3.4.2.jar:3.4.2]
    at sun.reflect.GeneratedMethodAccessor90.invoke(Unknown Source) ~[na:na]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) ~[mybatis-spring-1.3.1.jar:1.3.1]
    ... 52 common frames omitted

錯誤分析及解決方法:

       錯誤原因:在於sql中test="zoneId!=null and !&quot;&quot;.equals(zoneId.trim())"條件判斷,在mybatis解析sql的時候,會將test中的屬性解析為bean的

屬性,mybatis解析獲取值的時候通過getProperty的方法獲取,同理,當sql從數據庫查到數值,將屬性值賦值給屬性的時候通過setProperty方法。由於

mybatis將接口中的String參數解析為bean屬性,就需要有set,get方法,set,get方法一般都寫在實體類中,接口中的屬性可以通過@Param()注解來實現

set,get方法。

      修改方法:

public int getClientTotal(@Param("zoneId")String zoneId);

然后重新啟動就ok了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



猜您在找 Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'company' in 'class java.lang.String' org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'parentId' in 'class java.lang.String' nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'enterpriseId' in 'class java.lang.String' 已解決: mybatis報錯 org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'xxx' in 'class java.lang.String' Mybatis筆記四:nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'id' in 'class java.lang.String' 【Mybatis】mybatis查詢報錯org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'areaName' in 'class java.lang.String' mybatis映射異常:nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'id' in 'class java.lang.String org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'userId' in 'class java.lang.Integer' Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'ItemsCustom' in 'class com.pojo.OrderDetailCustom Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'empid' in 'class cn.happy.entity.Emp'
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM