亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

老師,我有個問題想問一下,我用MyBaits+set標簽更新,給我報了綁定異常,下面是代碼

異常信息:
org.apache.ibatis.exceptions.PersistenceException:?
###?Error?updating?database.??Cause:?org.apache.ibatis.binding.BindingException:?Parameter?'lastName'?not?found.?Available?parameters?are?[1,?0,?param1,?param2]
###?Cause:?org.apache.ibatis.binding.BindingException:?Parameter?'lastName'?not?found.?Available?parameters?are?[1,?0,?param1,?param2]
	at?org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at?org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200)
	at?org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62)
	at?org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
	at?com.sun.proxy.$Proxy3.updateEmpsTestSet(Unknown?Source)
	at?com.lesson.mybatis.test.MybatisTest.test05(MybatisTest.java:140)
	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:47)
	at?org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at?org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at?org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at?org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at?org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at?org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at?org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at?org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at?org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at?org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at?org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at?org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	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.binding.BindingException:?Parameter?'lastName'?not?found.?Available?parameters?are?[1,?0,?param1,?param2]
	at?org.apache.ibatis.binding.MapperMethod$ParamMap.get(MapperMethod.java:202)
	at?org.apache.ibatis.scripting.xmltags.DynamicContext$ContextAccessor.getProperty(DynamicContext.java:115)
	at?org.apache.ibatis.ognl.OgnlRuntime.getProperty(OgnlRuntime.java:2671)
	at?org.apache.ibatis.ognl.ASTProperty.getValueBody(ASTProperty.java:114)
	at?org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
	at?org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:258)
	at?org.apache.ibatis.ognl.ASTNotEq.getValueBody(ASTNotEq.java:50)
	at?org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
	at?org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:258)
	at?org.apache.ibatis.ognl.ASTAnd.getValueBody(ASTAnd.java:61)
	at?org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
	at?org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:258)
	at?org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:470)
	at?org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:434)
	at?org.apache.ibatis.scripting.xmltags.OgnlCache.getValue(OgnlCache.java:44)
	at?org.apache.ibatis.scripting.xmltags.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:32)
	at?org.apache.ibatis.scripting.xmltags.IfSqlNode.apply(IfSqlNode.java:34)
	at?org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:33)
	at?org.apache.ibatis.scripting.xmltags.TrimSqlNode.apply(TrimSqlNode.java:55)
	at?org.apache.ibatis.scripting.xmltags.MixedSqlNode.apply(MixedSqlNode.java:33)
	at?org.apache.ibatis.scripting.xmltags.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:41)
	at?org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:292)
	at?org.apache.ibatis.executor.statement.BaseStatementHandler.<init>(BaseStatementHandler.java:64)
	at?org.apache.ibatis.executor.statement.PreparedStatementHandler.<init>(PreparedStatementHandler.java:40)
	at?org.apache.ibatis.executor.statement.RoutingStatementHandler.<init>(RoutingStatementHandler.java:46)
	at?org.apache.ibatis.session.Configuration.newStatementHandler(Configuration.java:558)
	at?org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:48)
	at?org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
	at?org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
	at?org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
	...?27?more

配置文件:
<update?id="updateEmpsTestSet">
????UPDATE?tb_employees
????<set>
????????<if?test="lastName?!=?null?and?lastName?!=?&quot;&quot;">
	????lastName?=?#{param1.lastName},
	</if>
			
	<if?test="gender?!=?null?and?gender?!=?&quot;&quot;">
	????gender?=?#{param1.gender},
	</if>
			
	<if?test="email?!=?null?and?email?!=?&quot;&quot;">
	????email?=?#{param1.email}
	</if>
????</set>
		
????<!--?<trim?prefix="set"?suffixOverrides=",">
????????<if?test="lastName?!=?null?and?lastName?!=?&quot;&quot;">
	????lastName?=?#{param1.lastName},
	</if>
			
	<if?test="gender?!=?null?and?gender?!=?&quot;&quot;">
	????gender?=?#{param1.gender},
	</if>
			
	<if?test="email?!=?null?and?email?!=?&quot;&quot;">
	????email?=?#{param1.email}
	</if>
????</trim>?-->
	WHERE?id?=?#{param2}
</update>

接口方法:
public?int?updateEmpsTestSet(Employee?employee,Long?id);

測試方法:
@Test
public?void?test05()?{
		
????//一個SqlSession代表和數據庫的一次會話,用完之后必須關閉
????SqlSession?session?=?null;
????try?{
	session?=?SessionUtil.getSession();
	EmployeeMapper?mapper?=?session.getMapper(EmployeeMapper.class);
	Employee?employee?=?new?Employee();
	employee.setLastName("Pandas");
	employee.setGender('男');
	employee.setEmail("[email protected]");
			
	int?index?=?mapper.updateEmpsTestSet(employee,new?Long(7));
	System.out.println("==============================>"+index);
			
	session.commit();
????}?catch?(IOException?e)?{
	//?TODO?Auto-generated?catch?block
	e.printStackTrace();
????}?finally{
	if?(session?!=?null)?{
	????SessionUtil.closeSession(session);
????????}
????}
}


正在回答

1 回答

test里面的條件寫錯了,lastName 都要換成 parm1.lastName.如:

?<if?test="param1.lastName?!=?null?and?lastName?!=?&quot;&quot;">

? ? ?


0 回復 有任何疑惑可以回復我~
#1

坐著竹筏漂流 提問者

非常感謝!
2018-01-02 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

老師,我有個問題想問一下,我用MyBaits+set標簽更新,給我報了綁定異常,下面是代碼

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號