MyBatis注解模式取参数方法
生活随笔
收集整理的這篇文章主要介紹了
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取值
二:使用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注解模式取参数方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jvm初体验
- 下一篇: [coco2d]pageView:add