亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

MyBatis3傳遞多個參數(shù)(Multiple Parameters)

瀏覽:3日期:2023-10-23 15:54:37

傳遞多個參數(shù)一般用在查詢上,比如多個條件組成的查詢,有以下方式去實現(xiàn):

版本信息:

MyBatis:3.4.4

1、自帶方法

<select resultMap='resultUserArticleList'> select user.id,user.userName,user.userAddress,article.id as aid,article.title,article.content from user,article where user.id=article.userid and user.id=#{arg0} limit #{arg1},#{arg2} </select>

public List<Article> getUserArticlesByLimit(int id,int start,int limit);List<Article> articles=userMapper.getUserArticlesByLimit(1,0,2);

說明,arg0...也可以寫成param0...

2、直接傳遞對象

<select parameterType='Article' resultType='Article'> select * from article where 1 = 1 <if test='title != null'> and title = #{title} </if> <if test='content != null'> and content = #{content} </if> limit 1 </select>

public Article dynamicIfTest(Article article);Article inArticle = new Article();inArticle.setTitle('test_title');Article outArticle = userOperation.dynamicIfTest(inArticle);

3、使用@Praam標注

<select resultType='Article'> select * from article where 1 = 1 <choose> <when test='title != null'>and title = #{title} </when> <when test='content != null'>and content = #{content} </when> <otherwise>and tile = 'test_title' </otherwise> </choose> </select>

public Article dynamicChooseTest( @Param('title') String title, @Param('content') String content);Article outArticle2 = userOperation.dynamicChooseTest('test_title',null);

說明:這種方法同樣可以用在一個參數(shù)的時候。

4、使用HashMap

<select resultType='ArticleBean'>select * from article where id = #{id} and name = #[code] </select>

說明:parameterType='hashmap'可以不用寫。

public List<ArticleBean> getArticleBeanList(HashMap map);

HashMap<String, Object> map = new HashMap<String, Object>();map.put('id', 1);map.put('code', '123');List<Article> articless3 = userOperation.getArticleBeanList(map);

特殊的HashMap示例,用在foreach節(jié)點:

<select resultType='Article'> select * from article where title like '%'#{title}'%' and id in <foreach collection='ids' index='index' item='item' open='(' separator=',' close=')'> #{item} </foreach> </select>

public List<Article> dynamicForeach3Test(Map<String, Object> params);

HashMap<String, Object> map = new HashMap<String, Object>();map.put('title', 'title');map.put('ids', new int[]{1,3,6});List<Article> articless3 = userOperation.dynamicForeach3Test(map);

5、List結(jié)合foreach節(jié)點一起使用

<select resultType='Article'> select * from article where id in <foreach collection='list' index='index' item='item' open='(' separator=',' close=')'> #{item} </foreach> </select>

public List<Article> dynamicForeachTest(List<Integer> ids);

List<Integer> ids = new ArrayList<Integer>();ids.add(1);ids.add(3);ids.add(6);List<Article> articless = userOperation.dynamicForeachTest(ids);

6、數(shù)組結(jié)合foreach節(jié)點一起使用

<select resultType='Article'> select * from article where id in <foreach collection='array' index='index' item='item' open='(' separator=',' close=')'> #{item} </foreach> </select>

public List<Article> dynamicForeach2Test(int[] ids);

int[] ids2 = {1,3,6};List<Article> articless2 = userOperation.dynamicForeach2Test(ids2);

參考:

http://www.yihaomen.com/article/java/426.htm

到此這篇關(guān)于MyBatis3傳遞多個參數(shù)(Multiple Parameters)的文章就介紹到這了,更多相關(guān)MyBatis3傳遞多個參數(shù)內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

相關(guān)文章:
主站蜘蛛池模板: 亚洲丁香婷婷综合久久六月 | 久久永久免费视频 | 国产高清精品入口麻豆 | 久久精品国产精品亚洲精品 | 自拍视频第一页 | 成年大片免费高清在线看黄 | 色综合中文字幕天天在线 | 国产高清免费在线观看 | 国产在线精品视频 | 老司机成人午夜精品福利视频 | 一级做a毛片免费视频 | 222在线看片免费 | 久久青草免费91观看 | 色婷婷av777| 黄色免费a级片 | 欧美一级特黄aa大片在线观看免费 | 国产成人精品cao在线 | 成人深夜福利在线播放不卡 | 之后3在线观看完整免费酷客 | 国产香蕉视频在线播放 | a级日本乱理伦片免费入 | 国产亚洲美女精品久久久久 | 香蕉视频视频 | 日本国产最新一区二区三区 | 亚洲国产成人久久综合碰 | 国产精品啪 | 激情九月婷婷 | 国产精品入口麻豆高清 | 宅男午夜剧场 | 一级国产精品一级国产精品片 | 欧美日韩亚洲一区二区三区在线观看 | 免费黄色在线 | 久久精品嫩草影院免费看 | 免费看影片的网站入口 | 天天操综| 欧美色影视| 99精品国内不卡在线观看 | 无码日韩精品一区二区免费 | www.爱色| 免费黄色在线看 | 国产中文字幕在线 |