zoukankan      html  css  js  c++  java
  • 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了。

  • 相关阅读:
    POI2012 (持续更新中)
    [BZOJ2797][Poi2012]Squarks
    [BZOJ2796][Poi2012]Fibonacci Representation
    [BZOJ2791][Poi2012]Rendezvous
    [BZOJ2795][Poi2012]A Horrible Poem
    [BZOJ2794][Poi2012]Cloakroom
    纸张概率/期望题
    2016-5-11授课
    bzoj4519: [Cqoi2016]不同的最小割
    poj3693 Maximum repetition substring
  • 原文地址:https://www.cnblogs.com/zjdxr-up/p/8587990.html
Copyright © 2011-2022 走看看