SpringBlade 批量添加

一、对象映射

OrderImportDetail detail = new OrderImportDetail();
BeanUtil.copy(detailDTOs.get(i), detail);
details.add(detail);

二、批量添加

orderImportDetailService.saveBatch(details);

三、基类修改

批量添加的时候,一些默认的字段是没有赋值的,所以需要更改一下基类的方法

1、BaseServiceImpl.java

	/**
	 * 公用字段赋值
	 * @param entity 实体
	 */
	private void setPublicField(T entity) {
		BladeUser user = SecureUtil.getUser();
		if (user != null) {
			entity.setCreateUser(user.getUserId());
			entity.setUpdateUser(user.getUserId());
		}
		Date now = DateUtil.now();
		entity.setCreateTime(now);
		entity.setUpdateTime(now);
		if (entity.getStatus() == null) {
			entity.setStatus(BladeConstant.DB_STATUS_NORMAL);
		}
		entity.setIsDeleted(BladeConstant.DB_NOT_DELETED);
	}


	@Override
	public boolean saveBatch(Collection<T> entityList) {
		for (T entity : entityList) {
			setPublicField(entity);
		}
		return super.saveBatch(entityList);
	}

2、截图


posted @ 2020-10-27 16:12  古兴越  阅读(268)  评论(0)    收藏  举报