Mybatis-plus 使用xml进行调用
mybatis-plus 使用xml进行调用
1.创建xml文件
创建层级目录a.dao.mapper(而不是创建一个目录名字叫a.dao.mapper)
创建文件ContactMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="delta.dao.mapper.ContactMapper">
<insert id="batchInsertContact" useGeneratedKeys="true" keyProperty="id" parameterType="java.util.List">
insert ignore into delta_contact(en_name, cn_name, email, phone, wechat, create_time, update_time, create_user, update_user, yn)
values
<foreach collection="contactList" item="contact" index="index" separator=",">
(
#{contact.enName}, #{contact.cnName}, #{contact.email}, #{contact.phone}, #{contact.wechat},
#{contact.createTime}, #{contact.updateTime}, #{contact.createUser}, #{contact.updateUser}, ${contact.yn}
)
</foreach>
ON DUPLICATE KEY UPDATE
cn_name=values(cn_name),
email=values(email),
phone=values(phone),
wechat=values(wechat),
update_time = values(update_time),
update_user = values(update_user),
yn = values(yn)
</insert>
</mapper>
2.开启xml文件识别扫描
mybatis-plus.mapper-locations=classpath*:delta/dao/mapper/*Mapper.xml
3.相关mapper接口中添加方法
public interface ContactMapper extends ExternalMapper<Contact>{
void batchInsertContact(@Param("contactList") List<Contact> contactList);
}
4.剩下就是方法调用了
contactMapper.batchInsertContact(Lists.newArrayList(contact));
原创:做时间的朋友