Mybatis报错 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'parentCode' not found. Available parameters are [0, 1, param1, param2]
orcal数据库使用mybatis接收参数,如果传的是多个参数,需要使用#{0},#{1},。。。等代替具体参数名,0 代表第一个参数,1 代表第二个参数,以此类推。
错误语句:
<select id = "findNameByCode" resultMap="resultMap"> select name,code from table <where> code = #{code} and name = #{name} </where> </select>
正确语句:
<select id = "findNameByCode" resultMap="resultMap"> select name,code from table <where> code = #{0} and name = #{1} </where> </select>
如果需要对参数使用<if>进行判断的话,需要在XXXDAO.java接口层使用@Param注解 : void get(@Param("value") String name); 注: @Param中的参数需要跟 <if test=""> 中的判读参数一致, eg : 使用上面的DAO接口,Mapper中判断 : <if test="value != null and value != ''">