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. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Coul...ErrorDatabaseSpringFrameworkJDBCOTGException
- vue報錯之Duplicate keys detected: '0'. This may cause an update error.VueError
- 使用mybatis報錯:Error setting non null for parameter #4 with JdbcType TIMESTAMPMyBatisErrorNullJDBC
- [轉]Android Studio匯入工程報錯 Error:Cause: peer not authenticated 解決方案AndroidError
- MySQL過程報 Parameter number N is not an OUT parameter錯誤MySql
- Caused by: org.apache.ibatis.binding.BindingException: Parameter 'parameter' not found.解決ApacheBATException
- One cause leads to the error(The specified nodes are not clusterable)Error
- vipca報錯 Error 0PCAError
- Error querying database. XXXXXXXXXXXXX, No database selected。ErrorDatabase
- ERROR 1045 (28000): ProxySQL Error: 報錯ErrorSQL
- org.apache.ibatis.binding.BindingException: Parameter 'xxx' not found.ApacheBATException
- error:declared inside parameter listErrorIDE
- MYSQL SOURCE報錯 ERROR: ASCIIMySqlErrorASCII
- Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause:...ApacheBATUIExceptionErrorSQLAPP
- mysql報錯ERROR 1093MySqlError
- 【Redis】slaveof 報錯 Background transfer errorRedisError
- Oracle安裝報錯syntax errorOracleError
- struts2報Error filterStart錯ErrorFilter
- 網站報錯:“Database Server Error”網站DatabaseServerError
- Ubuntu 系統 apt 報錯:relocation errorUbuntuAPTError
- pip install scrapy報錯:error: UnableError
- MySQL報錯 Error_code: 1045MySqlError
- 反序列 unserialize(): Error 報錯問題Error
- Q:[Vue warn]: Duplicate keys detected: ‘PAYACT‘. This may cause an update error.VueError
- weblogic報錯: OPatch failed with error code 73WebAIError
- redis報錯Windows error 0x70RedisWindowsError
- 360 Atals:Cause: java.sql.SQLException: Proxy Warning - near “status“: syntax errorJavaSQLExceptionError
- 解決 java 實體中用 LocalDateTime 在轉換時候報錯 Error attempting to get column ‘XXX’ from result set. Cause: java.sql.JavaLDAErrorSQL
- ogg報錯error 11, Resource temporarily unavailableErrorAI
- ElasticSearch啟動報錯 ERROR: [4] bootstrap checks failedElasticsearchErrorbootAI
- cmake報錯CMake Error: Could not find CMAKE_ROOTError
- linux系統報錯AER PCIe Bus ErrorLinuxError
- 執行flutter run命令報錯::ERROR: Could not connect to lockdownd, error code -17FlutterError
- startup upgrade 時報錯ORA-00600: internal error code, arguments: [kmgs_parameter_update_timeout_1]Error
- standby database to primary database.Database
- Delete indexes to free database.deleteIndexDatabase
- 使用Boost庫報error C4996錯誤Error996
- win10 驅動簽名 報錯,Error =52Win10Error