在mybatis中进行批量操作

1、批量删除


	delete from FIN_PRODUCT_COLLECT 
	where fin_product_id in 
	#{item}
	and fin_consult_id=#{finConsultId}

 

String[] deleteIdsArray = deleteIds.split(",");
List finProductIds = new ArrayList();
for(int i=0; i parameters = new HashMap();
parameters.put("finConsultId", finConsultId);
parameters.put("finProductIds", finProductIds);
dao.deleteCollect(parameters);

 

2、批量添加

    1)范例一


	insert all 
	into FIN_PRODUCT_COLLECT (fin_consult_id,fin_product_id) values(col1, col2)  
	
	select #{finConsultId} as col1, #{item} as col2 from dual
	

 

String[] insertIdsArray = insertIds.split(",");
List finProductIds = new ArrayList();
for(int i=0; i map = new HashMap();
map.put("finConsultId", finConsultId);
map.put("finProductIds", finProductIds);
dao.insertCollect(map);

 

    2)范例二


	insert into page_logs (PAGE_TYPE, FILE_NAME, BORROW_NID, BORROW_TYPE, BORROW_NAME, CREATE_TIME) 
	values 
	
		(#{item.pageType}, #{item.fileName}, #{item.borrowNid}, #{item.borrowType}, #{item.borrowName}, #{item.createTime})
	

 

//mapper class method
public int batchInsert(List list);

public class PageLogsEntity {
	private Long id;
	private String pageType;
	private String fileName;
	private String borrowNid;
	private String borrowType;
	private String borrowName;
	private Date createTime;
}

 

你可能感兴趣的:(Java)