org.apache.ibatis.binding.BindingException: Parameter 'nickname' not found. Available parameters are

在使用mybatis遇到了一個找不到參數的問題,本着學習的態度跟了下源碼,通過一步一步的源碼發下,mybatis默認使用參數下標做爲參數名稱對參數賦值,即0、一、2等等這些參數名稱,只有當使用註解顯示標註參數名稱纔會使用指定的參數名稱,舉例說明狀況sql

        栗子1 apache

在mapper的xml文件中的sql以下mybatis

       select id,username,password  from u_user  where  username=#{username} and passsword=#{password}app

      mapper類中以下學習

     User  getUser(String username,String password)xml

     則上面寫法就會報org.apache.ibatis.binding.BindingException: Parameter 'nickname' not found錯誤get

緣由以下:源碼

org.apache.ibatis.binding.BindingException: Parameter nickname not found. Available parameters are [1, 0, param1, param2] - m15627293516 - 許康鑾我的博客

 解決辦法:博客

1 sql改成:select id,username,password  from u_user  where  username=#{0} and passsword=#{1}io

2 使用註解指定參數名稱:

User  getUser(@Param("username")String username,@Param("password")String password)

相關文章
相關標籤/搜索