mybatis和ibatis的一点区别

1. dao.xml命名空间的区别

mybatis:<mapper namespace="com.jd.yys.treaty.dao.read.TreatyInfoRDao"></mapper>

命名空间:dao接口的名称

ibatis:<sqlMap namespace="CardWare"></sqlMap>

命名空间,自定义的标识,调用的时候:return (List<CardWare>) queryForList("CardWare.queryCardWare", query);


2. 注入的时候写法不同(分页,sqlserver)

mybatis : 

   WITH cte as (
				select *,row_number() over(order by UpdateTime asc) as pageIndex from TreatyInfo(nolock) where yn = 1 and rfid is not null
		)  select t2.*,t1.pageIndex
     	from cte t1
     	inner join treatyInfo(nolock) t2
     	on t1.id=t2.id
      		where pageIndex between (#{page}-1)*#{pageSize}+1 and #{pageSize}*#{page}
ibatis:

WITH cte as (
				select *,row_number() over(order by id asc) as pageIndex from TreatyInfo(nolock) where yn = 1  
		)  select t2.*,t1.pageIndex
     	from cte t1
     	inner join treatyInfo(nolock) t2
     	on t1.id=t2.id
      		where pageIndex between (#page#-1)*#pageSize#+1 and #pageSize#*#page#

3. 参数和返回值的区别

mybatis: 

<select id="queryTreatyInfo" parameterType="Map"  resultType="TreatyInfo" >
ibatis:

 <select id="queryCardWare" parameterClass="map"  resultClass="cardWare" >

4. ibatis异常分析

Cause: org.xml.sax.SAXParseException: Attribute "parameterType" must be declared for element type "select".
原因:我在ibatis的select中写了parameterType和resultType。
正确做法:ibatis中用的是parameterClass和resultClass
SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0];
原因:我在注入对象的时候,其中有一个字段是int类型,但是数据库中保存的NULL,我的类用的是int,所以注入的时候转化错误。
解决方案:把类的int类型写成Interger。






你可能感兴趣的:(mybatis和ibatis的一点区别)