13.MyBatis報錯:Error querying database. Cause: org.apache.ibatis.binding.BindingException: Parameter
我做的功能是根據id和lastName查詢一條員工資訊記錄。
public Employee getEmpByIdAndLastName(Integer id,String lastName);
<select id="getEmpByIdAndLastName" resultType="com.fzl.mybatis.bean.Employee" databaseId="mysql">
select * from tbl_employee where id = #{id},last_name = #{lastName}
</select>
當傳遞多個引數給sql對映檔案時,報錯:
這個錯誤與mybatis處理引數機制有關。
當傳入多個引數的時候,mybatis會做特殊處理。多個引數會被封裝成一個map。其中,key:param1…paramN,或者引數的索引也可以,value:傳入的引數值。
而#{}就是從map中獲取指定的key的值;因此這時候,我們依然使用#{id},#{lastName}就會報錯。
解決辦法:
明確指定封裝引數時map的key;
public Employee getEmpByIdAndLastName(@Param("id") Integer id,@Param("lastName")String lastName);
這樣就可以了。
多個引數會被封裝成 一個map,
key:使用@Param註解指定的值
value:引數值
#{指定的key}取出對應的引數值
相關文章
- Error querying database. XXXXXXXXXXXXX, No database selected。ErrorDatabase
- vue報錯之Duplicate keys detected: '0'. This may cause an update error.VueError
- 使用mybatis報錯:Error setting non null for parameter #4 with JdbcType TIMESTAMPMyBatisErrorNullJDBC
- Caused by: org.apache.ibatis.binding.BindingException: Parameter 'parameter' not found.解決ApacheBATException
- [轉]Android Studio匯入工程報錯 Error:Cause: peer not authenticated 解決方案AndroidError
- org.apache.ibatis.binding.BindingException: Parameter 'xxx' not found.ApacheBATException
- Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause:...ApacheBATUIExceptionErrorSQLAPP
- ERROR 1045 (28000): ProxySQL Error: 報錯ErrorSQL
- 【Redis】slaveof 報錯 Background transfer errorRedisError
- 網站報錯:“Database Server Error”網站DatabaseServerError
- pip install scrapy報錯:error: UnableError
- Q:[Vue warn]: Duplicate keys detected: ‘PAYACT‘. This may cause an update error.VueError
- 解決 java 實體中用 LocalDateTime 在轉換時候報錯 Error attempting to get column ‘XXX’ from result set. Cause: java.sql.JavaLDAErrorSQL
- DataTables 1.10錯誤: requested unknown parameter
- Ubuntu 系統 apt 報錯:relocation errorUbuntuAPTError
- weblogic報錯: OPatch failed with error code 73WebAIError
- ogg報錯error 11, Resource temporarily unavailableErrorAI
- 反序列 unserialize(): Error 報錯問題Error
- 360 Atals:Cause: java.sql.SQLException: Proxy Warning - near “status“: syntax errorJavaSQLExceptionError
- Oracle dataguard報錯:Error 1017 received logging on to the standbyOracleError
- linux系統報錯AER PCIe Bus ErrorLinuxError
- 執行flutter run命令報錯::ERROR: Could not connect to lockdownd, error code -17FlutterError
- springboot開發介面報錯Optional int parameter 'userId' is present but cannot be translated into a null v......Spring BootNull
- appium start session 時報錯 Error executing adbExec. Original error 求指點APPSessionError
- VUE: npm run dev報錯Error: error:0308010C:digital envelope routines::unsupportedVueNPMdevErrorGit
- cmake報錯CMake Error: Could not find CMAKE_ROOTError
- MySQL 啟動報錯 error while loading shared librariesMySqlErrorWhile
- 使用Boost庫報error C4996錯誤Error996
- 【ERROR】su user報'This account is currently not available'錯誤 for linuxErrorAILinux
- ssh-add 報錯:Error connecting to agent No such file or directoryError
- ElasticSearch啟動報錯 ERROR: [4] bootstrap checks failedElasticsearchErrorbootAI
- GTID複製報錯處理:Last_Error: Error 'Can't drop database 'test';ASTErrorDatabase
- win10 驅動簽名 報錯,Error =52Win10Error
- rabbitMq的status報錯Error: unable to perform an operation on node ‘rabbit……MQErrorORM
- AndroidStudio編譯時報錯Error:Please select Android SDKAndroid編譯Error
- MySQL建立觸發器時報錯Error Code: 1064MySql觸發器Error
- 19c ADG報錯Error 1094 attaching to RFS for reconnectError
- MySQL 5.6複製報錯Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND;MySqlError