public MainMessageEntity buildInsert(Long userId, Integer tenantId) {
return MainMessageEntity.builder()
.messType(messType)
.messTitle(messTitle)
.messContent(messContent)
.publishTime(publishTime)
.publishUser(publishUser)
.status(SysMessageStatusEnum.MSG_STATUS_DRAFT)
.createTime(LocalDateTime.now())
.lastModifyTime(LocalDateTime.now())
.createUser(userId)
.tenantId(tenantId)
.lastModifyUser(userId)
.messReceiveRoleId(Joiner.on(",").join(roleIds))
.messReceiveRoleName(Joiner.on(",").join(roleName))
.build();
}
通过Joiner.on(",").join(roleIds) 将list<Long> 属性 roleIds 转换成字符串messReceiveRoleId 保存
另外一种方法
public MainMessageEntity buildUpdate(Long userId, Integer tenantId) {
return MainMessageEntity.builder()
.id(id)
.messType(messType)
.messTitle(messTitle)
.messContent(messContent)
.publishTime(publishTime)
.publishUser(publishUser)
.lastModifyTime(LocalDateTime.now())
.lastModifyUser(userId)
.tenantId(tenantId)
.messReceiveRoleId(roleIds.stream().map(n->String.valueOf(n)).collect(Collectors.joining(",")))
.messReceiveRoleName(roleName.stream().map(n->String.valueOf(n)).collect(Collectors.joining(",")))
.build();
}
通过 roleIds.stream().map(n->String.valueOf(n)).collect(Collectors.joining(",")) 也可以实现转换。