Mybatis与iBatis的主要差异对比
   
    他们都是优秀的持久层框架,MyBatis是现在最常用的持久层框架,可以动态地拼接sql语句,非常人性化,更适合逻辑复杂的sql;iBatis就是MyBatis前身,他们有很多相似的地方,今天主要讲一下sqlMap里面的变化。
    
    
     1. 传入参数
    
    
    iBatis是parameterClass,而MyBatis是可以不写的,也可以用parameterType;parameterClass,而MyBatis是可以不写的,也可以用parameterType;
    
    iBatis的传出参数关键字是:resultClass,而MyBatis是resultMap。
    
    iBatis:
    
     <select id="selectDeviceByWhere" parameterClass="Map" resultClass="BaseResultMap"> </select>
    
    
    MyBatis:
    
     <select id="selectDeviceByWhere" parameterType="Map" resultMap="BaseResultMap"> </select>
    
    
    
     2. 接收参数
    
    
    IBatis是使用# #和$
    
     KaTeX parse error: Expected ‘EOF’, got ‘#’ at position 23: …使用方法等同于MyBatis;#̲ #=#{ },
    
    
     
      
       = 
        =
      
      
       
        
        
        
         =
        
       
      
     
    
    { } ,解释一下#和
    
     KaTeX parse error: Expected ‘EOF’, got ‘#’ at position 5: 的区别,#̲字符串处理,加单引号,可以一定…
    
    直接使用,当传入的是数字时,用#会进行隐式转换为字符串,耗性能。IBatis是使用# #和$
    
     KaTeX parse error: Expected ‘EOF’, got ‘#’ at position 23: …使用方法等同于MyBatis;#̲ #=#{ },
    
    
     
      
       = 
        =
      
      
       
        
        
        
         =
        
       
      
     
    
    { } ,解释一下#和
    
     KaTeX parse error: Expected ‘EOF’, got ‘#’ at position 5: 的区别,#̲字符串处理,加单引号,可以一定…
    
    直接使用,当传入的是数字时,用#会进行隐式转换为字符串,耗性能。
    
    
     3. 判断语句,这个也是非常常用和重要的地方。
    
    
    对于MyBatis的很简单,只要在where 或者if 的标签里面添加test=””就可以了,里面写判断条件了。但是IBatis的就麻烦了许多了,它将每个都方法都进行了封装。例如
    
    isNull:判断property字段是否是null
   
<isNull prepend="and" property="id">   </isNull>
isEqual相当于equals,判断状态值。
<isEqual property="state" compareValue="0">  </isEqual>` 或
<isEqual property="state" compareProperty="nextState">  </isEqual>
isEmpty判断参数是否为Null或者空,满足其中一个条件则其true。
isNotEmpty相反,当参数既不为Null也不为空是其为true。
    
     4. 循环的使用
    
    
    iBatis是使用Iterate:这属性遍历整个集合,并为 java.util.List 集合中的元素重复元素体的内容。例如
   
<isNotEmpty property="deptIds">
		and dept_id in 
		<iterate property="deptIds" open="(" close=")" conjunction=",">
			#deptIds[]#
	        </iterate>
	</isNotEmpty>
    deptIds是数组类型的属性值,当deptIds不为null或“”时,进行deptIds遍历取值。
    
    MyBatis使用的是ForEach方法。他可以遍历List,
    
    
    ,Map三种元素。
    
    循环插入:
   
<insert id="xxxx" parameterType="CompilingRateDto">
	        insert into cm_compiling_rate (area)
	        values 
	        <foreach collection="compilingRateList" item="compilingRate"  separator="," >
	       		 (#{compilingRate.area})
	         </foreach>
	</insert>
循环更新:
<update id="xxxxx" parameterType="CompilingRateDto">
	        <foreach collection="updateCompilingRateList" item="compiling"  separator=";" >
		        update cm_compiling_rate cr
			      	set  compiling_manpower = #{compiling.compilingManpower},
			     where cr.valid_Month=#{compiling.validMonth}       	
		      </foreach>   	      
	 </update>
    
     5. MyBatis中一条sql结束后可以有“;”,而iBatis会报错
    
    
    
     6. 存储过程的调用
    
    
    iBatis:
   
 <procedure id="setCaseQueueStatus.sql" parameterMap="params.caseQueueStatus">
		<![CDATA[
	    	{call CMPCCDATA.PKG_CMPCC_QUEUE_TEASE.PROC_SET_AST_ACCT_STATUS(?,?)}
     		]]>
    </procedure>
   <parameterMap id="params.caseQueueStatus" class="java.util.Map">
	        <parameter property="P_ACCT_SN" jdbcType="VARCHAR" javaType="string" mode="IN" />
	        <parameter property="P_QUEUE_STATUS" jdbcType="VARCHAR" javaType="string" mode="IN" />
    </parameterMap>
MyBatis :
<select id="xxxxx"  resultType = "java.lang.String" statementType="CALLABLE">
   		{call batch_randomMark()}
</select>
通过 statementType 属性将该语句标识为存储过程而非普通 SQL 语句
 
