• Mybatis问题:There is no getter for property named 'unitId' in 'class java.lang.String'


    Mybatis遇到的问题

    问题:

    org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'unitId' in 'class java.lang.String'
        at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)
        at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)
        at com.sun.proxy.$Proxy6.selectList(Unknown Source)
        at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:198)
        at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119)
        at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
        at com.sun.proxy.$Proxy11.getUsersByUnitId(Unknown Source)
        at com.thinkPro.steap.db.base.sys.user.UserBase.getUsersByUnitId(UserBase.java:125)
        at com.thinkPro.steap.db.service.sys.user.UserService.getUsersByUnitId(UserService.java:188)
        at com.thinkPro.steap.test.TestUser.testGetUsersByUnitId(TestUser.java:184)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
        at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
    Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'unitId' in 'class java.lang.String'
        at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:380)
        at org.apache.ibatis.reflection.MetaClass.getGetInvoker(MetaClass.java:170)
        at org.apache.ibatis.reflection.wrapper.BeanWrapper.getBeanProperty(BeanWrapper.java:152)
        at org.apache.ibatis.reflection.wrapper.BeanWrapper.get(BeanWrapper.java:48)
        at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:116)
        at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextMap.get(DynamicContext.java:97)
        at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextAccessor.getProperty(DynamicContext.java:116)
        at org.apache.ibatis.ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1657)
        at org.apache.ibatis.ognl.ASTProperty.getValueBody(ASTProperty.java:92)
        at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
        at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210)
        at org.apache.ibatis.ognl.ASTNotEq.getValueBody(ASTNotEq.java:49)
        at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
        at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210)
        at org.apache.ibatis.ognl.ASTAnd.getValueBody(ASTAnd.java:56)
        at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
        at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210)
        at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:333)
        at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:310)
        at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:45)
        at org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:32)
        at org.apache.ibatis.scripting.xmltags.IfSqlNode.apply(IfSqlNode.java:33)
        at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:32)
        at org.apache.ibatis.scripting.xmltags.TrimSqlNode.apply(TrimSqlNode.java:54)
        at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:32)
        at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:40)
        at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:278)
        at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:75)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
        ... 32 more

    分析:

    那么什么情况下会发生“There is no getter for property named in ‘class java.lang.String’”错误呢?

    其实是在这种情况下:

        <select id="getRiskMember" resultMap="BaseResultMap" parameterType="String">
            <include refid="selectMember"/>
            and safetylevel > 1
            and stauts = 1
    
            <if test="username != null">
                and username = #{username} 
            </if>
        </select>

    注意看,是在if test=验证的时候发生的 “There is no getter for property named in ‘class java.lang.String’”,

    而并非是and username = #{username} 的时候发生的错误。

    解决办法:

      <select id="getRiskMember" resultMap="BaseResultMap" parameterType="String">
            <include refid="selectMember"/>
            and safetylevel > 1
            and stauts = 1
    
            <if test="_parameter != null">
                and username = #{username} 
            </if>
        </select>
  • 相关阅读:
    Sql Server2000里面获得数据库里面所有的用户表名称 和对应表的列名称
    c#开发windows应用程序几个小技巧
    "Unexpected Error 0x8ffe2740 Occurred" Error Message When You Try to Start a Web Site
    注册asp.net到iis
    O/R Mapping 影射文件生成的一点研究(暂时放在这里,实现以后再进行总结)
    WMI使用集锦
    NHibernate快速指南
    项目打包以前需要删除的文件
    Asp.Net 学习资源列表
    精彩Blog
  • 原文地址:https://www.cnblogs.com/haimishasha/p/5721188.html
Copyright © 2020-2023  润新知