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

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

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

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

傳遞多個(gè)參數(shù)一般用在查詢上,比如多個(gè)條件組成的查詢,有以下方式去實(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);

說(shuō)明,arg0...也可以寫(xiě)成param0...

2、直接傳遞對(duì)象

<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標(biāo)注

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

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

4、使用HashMap

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

說(shuō)明:parameterType='hashmap'可以不用寫(xiě)。

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é)點(diǎn):

<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é)點(diǎn)一起使用

<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é)點(diǎn)一起使用

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

相關(guān)文章:
主站蜘蛛池模板: 欧美一级专区免费大片俄罗斯 | 草久影院| 亚洲最大综合网 | 日韩中文字幕电影在线观看 | 美女国产网站 | 日韩亚洲欧美一区二区三区 | 一级aaaaaa毛片免费同男同女 | 久久精品视频免费在线观看 | 亚洲精品一区二区在线播放 | 亚洲综合资源 | 一级性黄色 | 亚洲高清色图 | 免费观看黄视频 | 亚洲欧美国产视频 | 黄色片在线免费看 | 亚洲自拍第二页 | 国产精品99久久久久久宅男 | 经典三级一区二区三区视频 | 黄色高清网站 | 麻豆视频在线免费看 | 国产全黄a一级毛片视频 | 亚洲国产日韩欧美高清片a 亚洲国产日韩欧美一区二区三区 | 国产精品嫩草免费视频 | 丁香婷婷激情综合 | 欧美精品一区二区三区免费播放 | 亚洲精品国产成人99久久 | 免费日韩在线观看 | 亚洲欧美二区三区久本道 | 看日本真人一一级特黄毛片 | 欧美中文字幕第一页 | 久久久久国产午夜 | 日本欧美中文字幕人在线 | 精品湿| 亚洲第一区第二区 | 国产网站视频 | 国产h视频在线观看高清 | 麻豆国产精品va在线观看不卡 | 欧美金8天国 | 女人精69xxxxx免费无毒 | 草草在线观看 | 精品国产一区二区三区成人 |