There is no getter for property named 'PRODUCT_ID' in 'class java.lang.String'
背景:心血来潮之际,准备搭建以下多月未曾碰触过的Mybatis框架,体验一番原生之美。殊不知能力有限,错误百出。特抒此文以纪念此坑。
问题:想在sql管理中来统一处理一些简单的判断,但是添加判断之后参数有问题。报如下错误:
报错:
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'PRODUCT_ID' in 'class java.lang.String' ### Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'PRODUCT_ID' in 'class java.lang.String' at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:107) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98) at www.daoimp.ProductDaoImp.findCode(ProductDaoImp.java:31) at www.test.Test.findCode(Test.java:47) at www.test.Test.main(Test.java:22) Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'PRODUCT_ID' in 'class java.lang.String' at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:377) at org.apache.ibatis.reflection.MetaClass.getGetInvoker(MetaClass.java:167) at org.apache.ibatis.reflection.wrapper.BeanWrapper.getBeanProperty(BeanWrapper.java:149) at org.apache.ibatis.reflection.wrapper.BeanWrapper.get(BeanWrapper.java:45) at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:113) at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextMap.get(DynamicContext.java:89) at org.apache.ibatis.scripting.xmltags.DynamicContext$ContextAccessor.getProperty(DynamicContext.java:107) 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.Ognl.getValue(Ognl.java:333) at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:413) at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:395) at org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:45) at org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:29) at org.apache.ibatis.scripting.xmltags.IfSqlNode.apply(IfSqlNode.java:30) at org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:29) at org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:37) at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:265) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:79) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104) ... 4 more
原因: 直接使用参数后异常那就用这种方式,没有什么说的出来的原因,能力还没有到给各位讲解的程度,先这样解决吧。
当前参数传递:
![](https://img2018.cnblogs.com/blog/1598981/201905/1598981-20190524172146862-1971996247.png)
解决方案:
![](https://img2018.cnblogs.com/blog/1598981/201905/1598981-20190524172337438-59949600.png)
![](https://img2018.cnblogs.com/blog/1598981/201905/1598981-20190524172730889-306345509.png)
至此:完美解决。