久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

mybatis不加@Parm注解報錯的解決方案

瀏覽:121日期:2023-10-21 12:44:03

我的idea版本2017.3.4,低版本貌似不會加上這個配置,idea高版本會

mybatis不加@Parm注解報錯的解決方案

補(bǔ)充知識:Mybatis傳多個參數(shù)的問題 及MyBatis報錯 Parameter ’0’ not found. Available parameters are [arg1, arg0, param1 問題

對于使用Mybatis ,傳多個參數(shù),我們可以使用對象封裝外,還可以直接傳遞參數(shù)

對象的封裝,例如查詢對象條件basequery對象

<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);

對應(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,因為這個標(biāo)簽只能指定一個參數(shù),而兩個參數(shù)及以上的,則不用再使用

第二:在sql語句里面以上的寫法是錯誤的(為了演示執(zhí)行報錯)

會報錯

Parameter ’0’ not found. Available parameters are [arg1, arg0, param1, param2]

注意這里使用的mybatis的版本號

在MyBatis3.4.4版不能直接使用#{0}要使用 #{arg0}

0是指參數(shù)的索引,從0開始。第一個參數(shù)是0,第二個參數(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>

剛剛說這樣的會報錯。解決辦法,更改mapper方法

加上@Param注解

selectByGameIdAndGoodsTypeId(@Param('gameTypeId')Long gameTypeId, @Param('goodsTypeId') Long goodsTypeId)

以上這篇mybatis不加@Parm注解報錯的解決方案就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Mybatis 數(shù)據(jù)庫
相關(guān)文章:
主站蜘蛛池模板: 楚雄市| 海原县| 浪卡子县| 彭州市| 辽宁省| 商都县| 石首市| 抚顺县| 黎城县| 深州市| 阿图什市| 晋江市| 友谊县| 鄂伦春自治旗| 汾西县| 高安市| 洛阳市| 大田县| 西丰县| 江源县| 长春市| 巩留县| 玛沁县| 上虞市| 陇西县| 郸城县| 白水县| 黑水县| 高州市| 余干县| 涪陵区| 万荣县| 嘉定区| 荆门市| 威信县| 盐津县| 弋阳县| 综艺| 肇庆市| 长春市| 荆州市|