java-maven-mybatis批量导入

作者在 2019-03-04 12:05:01 发布以下内容

mybatis的操作是对于dao层接口对应mapper里的同名xml,接口中的方法名对应xml里的同名select/update/insert/delete标签的id值,方法参数对应的是parameterType/parameterMap,方法的返回值对应的是resultType/resultMap。

对于mybatis的批量导入,当dao层接口的方法参数中使用@Param(value="insertOtherList")注解时,会将foreach标签的collection默认的值list修改为insertOtherList,此时在xml中处理时的写法是

dao层代码


import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.nssolsh.boot.modular.system.dao.ExeclAndDBBodyMapper;
import com.nssolsh.boot.modular.system.model.PSiDocBody;
import com.nssolsh.boot.modular.system.service.ExeclAndDBBodyService;

@Service
public class ExeclAndDBBodyServiceImpl  extends ServiceImpl<ExeclAndDBBodyMapper, PSiDocBody> implements ExeclAndDBBodyService {

	@Resource
	ExeclAndDBBodyMapper eam;
	
	@Override
	public int insertOtherBody(List<PSiDocBody> insertOtherList) {
		int flag = eam.insertOtherBody(insertOtherList);
		return flag;
	}
	
	
	/*@Override
	public void insertExeclBody(List<PSiDocBody> allDataList) {
		// TODO Auto-generated method stub
		
	}*/

}

对应的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="com.nssolsh.boot.modular.system.dao.ExeclAndDBBodyMapper">
	<resultMap id="aOtherResultMapBody" type="com.nssolsh.boot.modular.system.model.PSiDocBody" >
		<result column="item_cd" property="itemCd"/>
		<result column="item_type" property="item_type"/>
		<result column="density" property="density"/>
		<result column="start_row" property="start_row"/>
		<result column="end_row" property="end_row"/>
		<result column="file_id" property="file_id"/>
		<result column="extension_1" property="extension_1"/>
		<result column="extension_2" property="extension_2"/>
		<result column="extension_3" property="extension_3"/>
		<result column="extension_4" property="extension_4"/>
		<result column="extension_5" property="extension_5"/>
		<result column="create_user_cd" property="create_user_cd"/>
		<result column="create_date" property="create_date"/>
		<result column="record_user_cd" property="record_user_cd"/>
		<result column="record_date" property="record_date"/>
		<result column="su_code" property="su_code"/>
		<result column="su_name" property="su_name"/>
		<result column="sample_flg" property="sample_flg"/>
		<result column="psi_class" property="psi_class"/>
		<result column="record_class" property="record_class"/>
		<result column="year_month" property="year_month"/>
		<result column="customer_cd" property="customer_cd"/>
		<result column="customer_name" property="customer_name"/>
	</resultMap>
	<select id="selectMaxFileid" resultType="STRING">
		select max(file_id) as file_id from dbo.psi_file_info
	</select>
		
	<!-- 写入文件体 -->
	<insert id="insertOtherBody" parameterType="java.util.List">
		<selectKey resultType ="java.lang.Integer" keyProperty= "id"
                   order= "AFTER">
                  SELECT NEXT VALUE FOR seq_self_growth
        </selectKey >
		insert into dbo.psi_item_temp_info (
				item_cd,start_row,end_row,file_id,
				create_user_cd,create_date,record_user_cd,record_date
		) values
		<foreach collection ="insertOtherList" item="psibody" index= "index" separator =",">
			(#{psibody.itemCd},#{psibody.start_row},#{psibody.end_row},#{psibody.file_id},#{psibody.create_user_cd},
		#{psibody.create_date},#{psibody.record_user_cd},#{psibody.record_date}
		)
		</foreach>
	</insert>
</mapper>



java | 阅读 1383 次
文章评论,共2条
飞驰在路上
2019-03-05 21:35
1
看不懂咋办(--)
mooncharmzx(作者)
2019-03-07 11:08
2
以下是引用飞驰在路上在2019-03-05 21:35的发言1

看不懂咋办(--)
spring mvc框架分包一般都是control+service+serviceImp+dao(mapper),其中的如果dao层使用的是mybatis,一般情况下都是在mybatis的配置文件里指定文件映射关系,把mapper.java的java文件和对应的mybatis里的同名xml文件建立映射,而mapper.java的java文件里的方法名和xml里的select/update/insert/delete标签的id属性是对应的
游客请输入验证码