今天工做中遇到的一個問題,第二次了,忘記上次怎麼解決的了java
標記下spring
報錯信息sql
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'subejctrelid' in 'class java.lang.Integer' at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371) at com.sun.proxy.$Proxy16.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.$Proxy19.findIndiectSubejctRelRelationS(Unknown Source) at com.kbs.platform.service.impl.ARAnalysisServiceImpl.ARAnalysis(ARAnalysisServiceImpl.java:151) at com.kbs.service.ARServiceTest.test(ARServiceTest.java:41) 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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) 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:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'subejctrelid' in 'class java.lang.Integer' 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.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.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
主要信息apache
There is no getter for property named 'subejctrelid' in 'class java.lang.Integer'
找到一個相同的問題,大概意思是session
引發問題的緣由是由於在DAO方法中定義的參數 與 實體中定義的屬性不一致 致使的, 好比DAO方法定義的是: public int deleteUser(String userIds); SQL語句以下: <!-- 刪除用戶(邏輯刪除) --> <update id="deleteUser" parameterType="String"> UPDATE t_user t SET t.user_status = '禁用' WHERE t.user_pk_id IN(#{userIds}) </update> UserEntity的定義: public class UserEntity extends AbstractEntity{ private int userPkId; private String userId; private String userName; private String sex; private byte age; } 這個userIds並不在UserEntity中存在,而userId是存在的,若是使用UserEntity中不存在userIds的屬性 因此會報此錯誤。改爲userId 問題便可解決。
我經過改成map傳參能解決,不知道是我認識有誤仍是什麼問題,先標記下,有時間再測試一下mybatis
我是在作兩個表聯合查詢的時候遇到的,sql中用到了另外一張表的字段。結果集爲 整型app
語句以下eclipse
<select id="findIndiectSubejctRelRelations" resultType="java.lang.Integer" parameterType="java.lang.Integer" > select r.RelationId from subjectrel r,indirectrelation i where r.id=i.InDirectRelId <if test="subjectRelid!=null"> and i.SubjectRel = #{subjectRelid} </if> </select>
mapper是一開始這麼寫的:報上面的錯誤。測試
List<Integer> findIndiectSubejctRelRelations(Integer subjectRelid);
後來改成map傳值:lua
List<Integer> findIndiectSubejctRelRelations(Map map);
調用:
Map<String, Object> params=new HashMap<>(); params.put("subjectRelid", subjectRelPo.getId()); List<Integer> relations= subjectRelDao.findIndiectSubejctRelRelations(params);
測試經過。
估計是mybitas 有什麼機制吧,傳一個參數的時候會認爲這個參數必定是這個javabean的一個屬性。不然就會報錯