MyBatis In的使用

http://blog.csdn.net/unei66/article/details/17792503

 MyBatis In的使用
标签: mybatisin
2014-01-03 16:23 7454人阅读 评论(0) 收藏 举报
 分类: Java Web(12)
版权声明:本文为博主原创文章,未经博主允许不得转载。
目录(?)[+]
             项目中where条件中用到in,我理所当然的拼了个字符串传进去了,郁闷的是程序一直运行正常,测试case一直没有覆盖到这种情况,今天发现了,原来是程序的问题,我以为mybatis有bug呢。。。。。故记下此问题,留作笔记。

           1.解决方法(多参数)
               Map.xml

[html] view plaincopy在CODE上查看代码片派生到我的代码片
<select id="getEntityList" resultType="App" parameterType="map">
    select * from t_app
    where status=#{status}
    <if test="flag!=null ">
        and id not in
        <foreach item="item" index="index" collection="ids" open="("
            separator="," close=")">
            #{item}
        </foreach>
    </if>
</select>
          传入的参数为Map<String,Object>
          数据:status:1
                     ids:int[]{101,103,61,75}

         2.一个参数
            a.如果参数的类型是List, 则在使用时,collection属性要必须指定为 list
                           findByIds(List<Long> ids)

[html] view plaincopy在CODE上查看代码片派生到我的代码片
<select id="findByIdsMap" resultMap="BaseResultMap">  

         Select  

         <include refid="Base_Column_List" />  

         from jria where ID in
                  <foreach item="item" index="index" collection="list"
                         open="(" separator="," close=")">
                        #{item}
                </foreach>
  </select>   

           b.如果参数的类型是Array,则在使用时,collection属性要必须指定为 array
                     findByIds(Long[] ids)

[html] view plaincopy在CODE上查看代码片派生到我的代码片
<select id="findByIdsMap" resultMap="BaseResultMap">
                select
                <include refid="Base_Column_List" />
         from jria where ID in
                 <foreach item="item" index="index" collection="array"
                        open="(" separator="," close=")">
                       #{item}
               </foreach>
 </select>   
时间: 2024-08-25 22:24:33

MyBatis In的使用的相关文章

使用MyBatis Generator自动生成实体、mapper和dao层

通过MyBatis Generator可以自动生成实体.mapper和dao层,记录一下怎么用的. 主要步骤: 关于mybatis从数据库反向生成实体.DAO.mapper: 参考文章:http://www.cnblogs.com/wangkeai/p/6934683.html第一种方式:main方法运行(推荐) 1.在pom.xml中加入插件依赖: 2.写mbgConfiguration.xml文件,jdbc.properties文件 3.写/SSM/src/main/java/main/Ge

SSM整合(spring,spirngmvc,mybatis)

整合思路   准备环境:导入jar包(spring mybatis  dbcp连接池  mysql驱动包 log4j) 工程结构: --------------------------- 1.  整合dao mybatis和spring进行整合   applicationContext-dao.xml 配置: 1.数据源 2.SqlSessionFactory 3.mapper扫描器 创建po以及mapper(通过逆向工程,这里不再演示) 针对综合查询mapper,一般情况会有关联查询,建议自定

SpringBoot 2.SpringBoot整合Mybatis

一.创建Springboot的配置文件:application.properties SpringApplication 会从 application.properties 文件中加载配置信息,下面是添加Spring配置信息的文件目录顺序: 当前目录下的/config子目录中 当前目录中 一个 classpath 包下的 /config 目录中 classpath 根目录中 大家根据自己习惯来即可. /application.properties 文件配置如下: spring.datasourc

springMVC+MyBatis+Spring 整合(3)

spring mvc 与mybatis 的整合. 加入配置文件: spring-mybaits.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xm

MyBatis学习(四)XML配置文件之SQL映射的XML文件

SQL映射文件常用的元素: 1.select 查询语句是MyBatis最常用的语句之一. 执行简单查询的select元素是非常简单的: <select id="selectUser" parameterType="int" resultType="hashmap"> SELECT * FROM PERSON WHERE ID = #{id} </select> 这个语句被称作selectUser,接受一个int类型的参数,

MyBatis框架中Mapper映射配置的使用及原理解析(七) MapperProxy,MapperProxyFactory

从上文<MyBatis框架中Mapper映射配置的使用及原理解析(六) MapperRegistry> 中我们知道DefaultSqlSession的getMapper方法,最后是通过MapperRegistry对象获得Mapper实例: public <T> T getMapper(Class<T> type, SqlSession sqlSession) { final MapperProxyFactory<T> mapperProxyFactory =

2017年9月3日 Spring及Mybatis中连接数据库的不同方式

连接数据库用spring和mybatis中使用的方法可以不同,mybaits可以不用写数据库的配置文件 Spring的连接方法 <!-- 读取属性文件(.properties)的内容 --> <!-- location:指定要读取的属性文件的位置及文件名. 注: classpath:表示依据类路径去查找 容器依据路径读取属性文件的内容, 并且将这些内容存放到Properties对象上 --> //数据库的登入数据文件 //文件名db.properties #db connectio

mybatis中&quot;#&quot;和&quot;$&quot;的区别

mybatis中"#"和"$"的区别 动态 sql 是 mybatis 的主要特性之一,在 mapper 中定义的参数传到 xml 中之后,在查询之前 mybatis 会对其进行动态解析.mybatis 为我们提供了两种支持动态 sql 的语法:#{} 以及 ${}. 在下面的语句中,如果 username 的值为 zhangsan,则两种方式无任何区别: select * from user where name = #{name}; select * from

mybatis中的mapper接口文件以及example类的实例函数以及详解

##Example example = new ##Example(); example.setOrderByClause("字段名 ASC"); //升序排列,desc为降序排列. example.setDistinct(false)//去除重复,boolean型,true为选择不重复的记录. Criteria criteria = new Example().createCriteria(); is null;is not null; equal to(value);not equ

mybatis与hibernate的区别

本文转载自:http://blog.csdn.net/wangpeng047/article/details/17038659 以前没怎么用过mybatis,只知道与hibernate一样是个orm数据库框架.随着使用熟练度的增加,发现它与hibernate区别是非常大的,结合至今为止的经验,总结出以下几点: 1. hibernate是全自动,而mybatis是半自动. hibernate完全可以通过对象关系模型实现对数据库的操作,拥有完整的JavaBean对象与数据库的映射结构来自动生成sql