xiejun
2024-11-01 80b6cbfc9c861469146318d0b3dd5f8b8b525b8a
Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/convert/BladeConversionService.java
对比新文件
@@ -0,0 +1,50 @@
package org.springblade.core.tool.convert;
import org.springframework.boot.convert.ApplicationConversionService;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.lang.Nullable;
import org.springframework.util.StringValueResolver;
/**
 * 绫诲瀷 杞崲 鏈嶅姟锛屾坊鍔犱簡 IEnum 杞崲
 *
 * @author L.cm
 */
public class BladeConversionService extends ApplicationConversionService {
   @Nullable
   private static volatile BladeConversionService SHARED_INSTANCE;
   public BladeConversionService() {
      this(null);
   }
   public BladeConversionService(@Nullable StringValueResolver embeddedValueResolver) {
      super(embeddedValueResolver);
      super.addConverter(new EnumToStringConverter());
      super.addConverter(new StringToEnumConverter());
   }
   /**
    * Return a shared default application {@code ConversionService} instance, lazily
    * building it once needed.
    * <p>
    * Note: This method actually returns an {@link BladeConversionService}
    * instance. However, the {@code ConversionService} signature has been preserved for
    * binary compatibility.
    * @return the shared {@code BladeConversionService} instance (never{@code null})
    */
   public static GenericConversionService getInstance() {
      BladeConversionService sharedInstance = BladeConversionService.SHARED_INSTANCE;
      if (sharedInstance == null) {
         synchronized (BladeConversionService.class) {
            sharedInstance = BladeConversionService.SHARED_INSTANCE;
            if (sharedInstance == null) {
               sharedInstance = new BladeConversionService();
               BladeConversionService.SHARED_INSTANCE = sharedInstance;
            }
         }
      }
      return sharedInstance;
   }
}