com.feingto.cloud.domain.converters.SetPersistenceConverters Maven / Gradle / Ivy
package com.feingto.cloud.domain.converters;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.persistence.AttributeConverter;
import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Set、逗号连接字符串持久层转换
*
* @author longfei
*/
public class SetPersistenceConverters implements AttributeConverter, String> {
@Override
public String convertToDatabaseColumn(Set attribute) {
return CollectionUtils.isNotEmpty(attribute) ? String.join(",", attribute) : null;
}
@Override
public Set convertToEntityAttribute(String dbData) {
return StringUtils.hasText(dbData) ? Stream.of(dbData.split(",", -1)).collect(Collectors.toSet()) : Collections.emptySet();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy