1. 程式人生 > 實用技巧 >SpringBlade 批量新增

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、截圖