All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.feingto.cloud.domain.converters.ListPersistenceConverters Maven / Gradle / Ivy

There is a newer version: 2.3.5.RELEASE
Show newest version
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.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * List、逗号连接字符串持久层转换
 *
 * @author longfei
 */
public class ListPersistenceConverters implements AttributeConverter, String> {
    @Override
    public String convertToDatabaseColumn(List attribute) {
        return CollectionUtils.isNotEmpty(attribute) ? String.join(",", attribute) : null;
    }

    @Override
    public List convertToEntityAttribute(String dbData) {
        return StringUtils.hasText(dbData)
                ? Stream.of(dbData.split(",", -1)).collect(Collectors.toList())
                : Collections.emptyList();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy