日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

MyBatis注解模式取参数方法

發布時間:2024/4/17 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MyBatis注解模式取参数方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

@Select("select count(*) from (select id from patrol_host where hostName=#{hostName} ) tmp_count") public int isAAA(String hostName);@Select("select count(*) from (select id from patrol_host where ip=#{ip} and id<>#{id}) tmp_count") public int isBBB(String ip, Integer id);

第一種只有一個參數的時候可以直接使用#{hostName}取到參數

但是如果第二種有多個參數直接使用#{ip}是取不到的

個人理解:

由于當有多個參數的時候MyBatis會將所有參數放入一個map中,value是參數值,而Key默認是param1,param2...和0,1...因此直接使用#{ip}是取不到值的

取值方法:
一:使用數字key取值

@Select("select count(*) from (select id from patrol_host where ip=#{0} and id<>#{1}) tmp_count") public int isIpExistForUpdate(String ip, Integer id);

二:使用param來取值,

@Select("select count(*) from (select id from patrol_host where ip=#{param1} and id<>#{param2}) tmp_count") public int isIpExistForUpdate(String ip, Integer id);

以上兩種方法都需要注意順序.數字key是從0開始,param取值則是從param1開始

三:使用注解指定key值

@Select("select count(*) from (select id from patrol_host where ip=#{ip} and id<>#{id}) tmp_count") public int isIpExistForUpdate(@Param("ip")String ip, @Param("id")Integer id);

這種方式是直接使用注解中設置的key值來取值

?

轉載于:https://my.oschina.net/MrBamboo/blog/882119

總結

以上是生活随笔為你收集整理的MyBatis注解模式取参数方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。