1. ibatis3.*版本以后正式改名为mybaits,它也从apache转到了google code下;也就是说ibatis2.*,mybatis3.*。
2. 映射文件的不同
ibatis的配置文件如下
2.1 dtd约束文件不同
2.2 ibatis中根元素是sqlMapConfig,mybatis中是configuration;
2.3 settings属性的不同配置
ibatis中是
mybatis中是
2.5 数据库表的映射区别
ibatis中某表的映射文件
ID, CLASS_ID, PROPERTY_ID, INPUT_TYPE, SORT_NUM,
DESCRIPTION,
CREATED_DATE, CREATED_BY,
UPDATED_DATE, UPDATED_BY, STATUS,
IS_KEY, IS_SPU, IS_SALE, IS_PRODUCT,CHANNEL_ID,COMPANY_ID
P.ID, P.CLASS_ID, P.PROPERTY_ID, P.INPUT_TYPE, P.SORT_NUM,
P.DESCRIPTION,
P.CREATED_DATE,
P.CREATED_BY, P.UPDATED_DATE,
P.UPDATED_BY, P.STATUS, P.IS_KEY, P.IS_SPU,
P.IS_SALE,
P.IS_PRODUCT,P.CHANNEL_ID,P.COMPANY_ID
UPDATE
PP_CLASS_PROPERTY
SET STATUS = 1
where ID = #id:VARCHAR# AND
INSERT INTO PP_CLASS_PROPERTY
(
)
VALUES (#id:VARCHAR#, #classId:VARCHAR#,
#propertyId:VARCHAR#,
#inputType:VARCHAR#,
#sortNum:DECIMAL#,
#description:VARCHAR#,
#createdDate:TIMESTAMP#,
#createdBy:VARCHAR#,
#updatedDate:TIMESTAMP#,
#updatedBy:VARCHAR#, 0,#isKey:DECIMAL#,
#isSpu:DECIMAL#,
#isSale:DECIMAL#, #isProduct:DECIMAL#,
#channelId:VARCHAR#,
#companyId:VARCHAR#)
UPDATE PP_CLASS_PROPERTY
CLASS_ID =
#classId:VARCHAR#
PROPERTY_ID =
#propertyId:VARCHAR#
INPUT_TYPE =
#inputType:VARCHAR#
SORT_NUM =
#sortNum:DECIMAL#
DESCRIPTION =
#description:VARCHAR#
CREATED_DATE =
#createdDate:TIMESTAMP#
CREATED_BY =
#createdBy:VARCHAR#
UPDATED_DATE =
#updatedDate:TIMESTAMP#
UPDATED_BY =
#updatedBy:VARCHAR#
STATUS = #status:DECIMAL#
IS_KEY = #isKey:DECIMAL#
IS_SPU = #isSpu:DECIMAL#
IS_SALE = #isSale:DECIMAL#
IS_PRODUCT =
#isProduct:DECIMAL#
WHERE ID = #id:VARCHAR# AND
ID ,
LOGIN_NAME ,
LOGIN_PASS ,
USER_TYPE ,
REG_DATE ,
EMAIL ,
MOBILE ,
QQ ,
PHOTO ,
CARD_TYPE ,
CARD_VALUE ,
USER_NAME ,
USER_SEX ,
USER_BIR ,
USER_ADDR ,
JOB_NAME ,
JOB_ADDR ,
JOB_TEL ,
BORN_ADDR ,
USER_STATUS ,
ROLE_TYPE
order by ${orderByClause}
insert into SYS_USER (
)
values (
#{id,jdbcType=VARCHAR},
#{loginName,jdbcType=VARCHAR},
#{loginPass,jdbcType=VARCHAR},
#{userType,jdbcType=VARCHAR},
#{regDate,jdbcType=CHAR},
#{email,jdbcType=VARCHAR},
#{mobile,jdbcType=VARCHAR},
#{qq,jdbcType=VARCHAR},
#{photo,jdbcType=VARCHAR},
#{cardType,jdbcType=VARCHAR},
#{cardValue,jdbcType=VARCHAR},
#{userName,jdbcType=VARCHAR},
#{userSex,jdbcType=VARCHAR},
#{userBir,jdbcType=CHAR},
#{userAddr,jdbcType=VARCHAR},
#{jobName,jdbcType=VARCHAR},
#{jobAddr,jdbcType=VARCHAR},
#{jobTel,jdbcType=VARCHAR},
#{bornAddr,jdbcType=VARCHAR},
#{userStatus,jdbcType=INTEGER},
#{roleType,,jdbcType=VARCHAR}
)
insert into SYS_USER ( )
values
(
#{item.id,jdbcType=VARCHAR},
#{item.loginName,jdbcType=VARCHAR},
#{item.loginPass,jdbcType=VARCHAR},
#{item.userType,jdbcType=VARCHAR},
#{item.regDate,jdbcType=CHAR},
#{item.email,jdbcType=VARCHAR},
#{item.mobile,jdbcType=VARCHAR},
#{item.qq,jdbcType=VARCHAR},
#{item.photo,jdbcType=VARCHAR},
#{item.cardType,jdbcType=VARCHAR},
#{item.cardValue,jdbcType=VARCHAR},
#{item.userName,jdbcType=VARCHAR},
#{item.userSex,jdbcType=VARCHAR},
#{item.userBir,jdbcType=CHAR},
#{item.userAddr,jdbcType=VARCHAR},
#{item.jobName,jdbcType=VARCHAR},
#{item.jobAddr,jdbcType=VARCHAR},
#{item.jobTel,jdbcType=VARCHAR},
#{item.bornAddr,jdbcType=VARCHAR},
#{item.userStatus,jdbcType=INTEGER},
#{item.roleType,jdbcType=VARCHAR}
)
update SYS_USER
ID = #{id,jdbcType=VARCHAR},
LOGIN_NAME = #{loginName,jdbcType=VARCHAR},
LOGIN_PASS = #{loginPass,jdbcType=VARCHAR},
USER_TYPE = #{userType,jdbcType=VARCHAR},
REG_DATE = #{regDate,jdbcType=CHAR},
EMAIL = #{email,jdbcType=VARCHAR},
MOBILE = #{mobile,jdbcType=VARCHAR},
QQ = #{qq,jdbcType=VARCHAR},
PHOTO = #{photo,jdbcType=VARCHAR},
CARD_TYPE = #{cardType,jdbcType=VARCHAR},
CARD_VALUE = #{cardValue,jdbcType=VARCHAR},
USER_NAME = #{userName,jdbcType=VARCHAR},
USER_SEX = #{userSex,jdbcType=VARCHAR},
USER_BIR = #{userBir,jdbcType=CHAR},
USER_ADDR = #{userAddr,jdbcType=VARCHAR},
JOB_NAME = #{jobName,jdbcType=VARCHAR},
JOB_ADDR = #{jobAddr,jdbcType=VARCHAR},
JOB_TEL = #{jobTel,jdbcType=VARCHAR},
BORN_ADDR = #{bornAddr,jdbcType=VARCHAR},
USER_STATUS = #{userStatus,jdbcType=INTEGER},
ROLE_TYPE = #{roleType,jdbcType=VARCHAR},
where ID = #{id,jdbcType=VARCHAR}
update SYS_USER set
LOGIN_NAME = #{item.loginName,jdbcType=VARCHAR},
LOGIN_PASS = #{item.loginPass,jdbcType=VARCHAR},
USER_TYPE = #{item.userType,jdbcType=VARCHAR},
REG_DATE = #{item.regDate,jdbcType=CHAR},
EMAIL = #{item.email,jdbcType=VARCHAR},
MOBILE = #{item.mobile,jdbcType=VARCHAR},
QQ = #{item.qq,jdbcType=VARCHAR},
PHOTO = #{item.photo,jdbcType=VARCHAR},
CARD_TYPE = #{item.cardType,jdbcType=VARCHAR},
CARD_VALUE = #{item.cardValue,jdbcType=VARCHAR},
USER_NAME = #{item.userName,jdbcType=VARCHAR},
USER_SEX = #{item.userSex,jdbcType=VARCHAR},
USER_BIR = #{item.userBir,jdbcType=CHAR},
USER_ADDR = #{item.userAddr,jdbcType=VARCHAR},
JOB_NAME = #{item.jobName,jdbcType=VARCHAR},
JOB_ADDR = #{item.jobAddr,jdbcType=VARCHAR},
JOB_TEL = #{item.jobTel,jdbcType=VARCHAR},
BORN_ADDR = #{item.bornAddr,jdbcType=VARCHAR},
USER_STATUS = #{item.userStatus,jdbcType=INTEGER},
ROLE_TYPE = #{item.roleType,jdbcType=VARCHAR}
where ID = #{item.id,jdbcType=VARCHAR}
delete from SYS_USER
where ID = #{id,jdbcType=VARCHAR}
delete from SYS_USER
where ID in (
#{item.id,jdbcType=VARCHAR}
)
2.5.1 ibatis中根元素是sqlMap,mybatis中是mapper;
2.5.2 在 iBatis 中,namespace 不是必需的,且它的存在没有实际的意义。在 MyBatis 中,namespace 终于派上用场了,它使得映射文件与接口绑定变得非常自然。
2.5.3 ibatis中有resultMap和resultClass两种返回类型,resultMap是我们在ibatis的配置文件中定义的,也就是在配置文件中使用resultMap元素定义的;resultClass是指java语言中内置的类型,如:integer、java.util.HashMap等等;
mybatis中将两者统一为resultType,这样挺好的,开发者不用再记两个属性了。
2.5.4 ibatis中有parameterClass,mybatis中有parameterType,两者区别不大。
2.5.5 参数的写法比较
ibatis中写法,如代码片段:
WHERE ID = #id:VARCHAR#
mybatis中写法,如代码片段:
where ID = #{id,jdbcType=VARCHAR}
2.5.6 iBatis/MyBatis 调用存储过程的写法
{call swap_contact_name (?, ?,?)}