码迷,mamicode.com
首页 > 其他好文 > 详细

MyBatis(十一):Mybatis 参数传递用法

时间:2019-12-11 23:12:28      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:nal   color   title   model   多个参数   integer   参数   tis   href   

之前文章中对in的用法做过讲解:《MyBatis(四):mybatis中使用in查询时的注意事项

实际上对于多个参数的用法也是这是注意的:

用法1:多参&普通判空&List集合判空&in用法

@Options(useCache = true, flushCache = Options.FlushCachePolicy.FALSE, timeout = 60000)
    @Select(value = {
            "<script>",
            " SELECT  `id`,`title` ",
            " FROM `tb_article` ",
            " WHERE `category_id`=#{article.categoryId} ",
            "   <if test=‘article.status!=null‘>",
            "   AND `status` = #{article.status} ",
            "   </if>",
            "   <if test=‘typeList!=null and !typeList.isEmpty()‘>",
            "       and `article_type` in",
            "        <foreach collection=\"typeList\" index=\"index\" item=\"item\" open=\"(\" separator=\",\" close=\")\">",
            "           #{item} ",
            "        </foreach>",
            "   </if>",
            "</script>"
            })
    @ResultMap(value = {"articleResultMap"})
    List<AreaPo> queryByCondition(final @Param("article") ArticleModel article, final @Param("typeList") List<Integer> typeList);

1)上边主要对普通参数判断空用法:<if test=‘article.status!=null‘>

2)集合判空的用法:<if test=‘typeList!=null and !typeList.isEmpty()‘>

3)in的用法:<foreach collection=\"typeList\" index=\"index\" item=\"item\" open=\"(\" separator=\",\" close=\")\">";

4)多参数用法,实际上多个参数如果使用@SqlProvider方式是,在ArticleSqlProvider的类中方法中接收的参数对象为Map<String,Object>,该map集合中包含两个对象:key:article的ArticleModel对象;key:typeList的List<Integer>对象。获取方式:ArticleModel aritlce=(ArticleModel)map.get("aritcle");List<Integer> typeList=(List<Integer>)map.get("typeList");。

 

MyBatis(十一):Mybatis 参数传递用法

标签:nal   color   title   model   多个参数   integer   参数   tis   href   

原文地址:https://www.cnblogs.com/yy3b2007com/p/12026407.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!