mybatis不加@Parm注解報(bào)錯(cuò)的解決方案
我的idea版本2017.3.4,低版本貌似不會(huì)加上這個(gè)配置,idea高版本會(huì)
補(bǔ)充知識(shí):Mybatis傳多個(gè)參數(shù)的問(wèn)題 及MyBatis報(bào)錯(cuò) Parameter ’0’ not found. Available parameters are [arg1, arg0, param1 問(wèn)題
對(duì)于使用Mybatis ,傳多個(gè)參數(shù),我們可以使用對(duì)象封裝外,還可以直接傳遞參數(shù)
對(duì)象的封裝,例如查詢對(duì)象條件basequery對(duì)象
<select parameterType='com.niulande.product.query.BaseQuery' resultMap='BaseResultMap'> select <include refid='Base_Column_List' /> from pd_product <include refid='whereSql'/> </select> <sql > <where> <if test='gameCode != null and gameCode != ’’' > and game_type_coding = #{gameCode} </if> <if test='goodsTypeId != null'> and goods_type_id = #{goodsTypeId} </if> <if test='accId != null'> and account_id = #{accId} </if> <if test='delFlag != null'> and del_flag = #{delFlag} </if> </where> limit #{start},#{rows} </sql></mapper>
直接傳遞參數(shù)
例如:
mapper方法
selectByGameIdAndGoodsTypeId(Long gameTypeId, Long goodsTypeId);
對(duì)應(yīng)的xml文件方法:
<select resultMap='BaseResultMap'> select <include refid='Base_Column_List' /> from pd_game_goods_type_mid where game_type_id = #{gameTypeId} AND goods_type_id = #{goodsTypeId}</select>
第一:在select標(biāo)簽后就不再使用parameterType,因?yàn)檫@個(gè)標(biāo)簽只能指定一個(gè)參數(shù),而兩個(gè)參數(shù)及以上的,則不用再使用
第二:在sql語(yǔ)句里面以上的寫法是錯(cuò)誤的(為了演示執(zhí)行報(bào)錯(cuò))
會(huì)報(bào)錯(cuò)
Parameter ’0’ not found. Available parameters are [arg1, arg0, param1, param2]
注意這里使用的mybatis的版本號(hào)
在MyBatis3.4.4版不能直接使用#{0}要使用 #{arg0}
0是指參數(shù)的索引,從0開始。第一個(gè)參數(shù)是0,第二個(gè)參數(shù)是1,依次類推
以下正確的寫法:
<select resultMap='BaseResultMap'> select <include refid='Base_Column_List' /> from pd_game_goods_type_mid where game_type_id = #{arg0} AND goods_type_id = #{arg1}</select>
第三種:
<select resultMap='BaseResultMap'> select <include refid='Base_Column_List' /> from pd_game_goods_type_mid where game_type_id = #{gameTypeId} AND goods_type_id = #{goodsTypeId}</select>
剛剛說(shuō)這樣的會(huì)報(bào)錯(cuò)。解決辦法,更改mapper方法
加上@Param注解
selectByGameIdAndGoodsTypeId(@Param('gameTypeId')Long gameTypeId, @Param('goodsTypeId') Long goodsTypeId)
以上這篇mybatis不加@Parm注解報(bào)錯(cuò)的解決方案就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Windows NT平臺(tái)下Oracle優(yōu)化策略簡(jiǎn)介2. Oracle中利用ADO對(duì)象實(shí)現(xiàn)存取和訪問(wèn)3. MySQL全文搜索之布爾搜索4. MySql中流程控制函數(shù)/統(tǒng)計(jì)函數(shù)/分組查詢用法解析5. sqlserver數(shù)據(jù)庫(kù)導(dǎo)入方法的詳細(xì)圖文教程6. Oracle的PDB數(shù)據(jù)庫(kù)創(chuàng)建DIRECTORY時(shí)遇到ORA-65254問(wèn)題及解決方法7. Oracle數(shù)據(jù)庫(kù)中SQL語(yǔ)句性能調(diào)整原則8. MySQL 的啟動(dòng)選項(xiàng)和系統(tǒng)變量實(shí)例詳解9. SQL Server和Oracle并行處理方法對(duì)比10. navicat導(dǎo)入oracle導(dǎo)出的dmp文件
