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

coo.mvc.converter.StringToUuidEntity Maven / Gradle / Ivy

package coo.mvc.converter;

import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory;

import coo.core.hibernate.dao.DaoUtils;
import coo.core.model.UuidEntity;

/**
 * 字符串转换成UuidEntity转换器工厂。
 */
public class StringToUuidEntity implements ConverterFactory {
	@Override
	public  Converter getConverter(
			Class targetType) {
		return new StringToUuidEntityConverter(targetType);
	}

	/**
	 * 字符串转换成UuidEntity转换器。
	 */
	private class StringToUuidEntityConverter implements
			Converter {
		private final Class toClass;

		/**
		 * 构造方法。
		 * 
		 * @param toClass
		 *            转换目标类
		 */
		public StringToUuidEntityConverter(Class toClass) {
			this.toClass = toClass;
		}

		/**
		 * 将字符串值转换为UuidEntity对象。
		 * 
		 * @param source
		 *            字符串值
		 * @return 返回UuidEntity对象。
		 */
		public T convert(String source) {
			if (source.length() == 0) {
				return null;
			}
			return (T) DaoUtils.getEntity(toClass, source.trim());
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy