<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mappernamespace="com.benmu.mts.wx.center.service.dao.CustomDialogDao"> <updateid="updateDialogByFrom2"parameterType="com.benmu.mts.wx.center.custom.bean.CustomDialog"> update custom_dialog <set> <iftest="status != null"> status = #{status} </if> </set> where 1=1 and appid = #{appid} and fromUser = #{fromUser} </update> </mapper>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'status' not found. Available parameters are [param, fromUser, appid, param3, param1, param2] at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:76) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399) at com.sun.proxy.$Proxy27.update(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:269) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:55) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53) at com.sun.proxy.$Proxy28.updateDialogByFrom2(Unknown Source) at com.benmu.mts.wx.center.dao.CustomDialogDaoTest.updateDialogByFrom2(CustomDialogDaoTest.java:54) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
1 2 3 4 5 6 7 8 9
<updateid="updateDialogByFrom2" > update custom_dialog <set> <iftest="param.status != null"> status = #{param.status} </if> </set> where 1=1 and appid = #{appid} and from_user = #{fromUser} </update>
Dao 层已经把 CustomDialog 定义成了 param,如果要使用 status,就要调用 param 这个对象的属性,否则 status 是找不到的