package com.gkhy.safePlatform.safeCheck.util; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import java.text.SimpleDateFormat; import java.util.Date; @Component public class ConsolePrintIfEnvIsDevUtil { private static String currentActiveEnv; private static Boolean currentEnvIsDev = false; @Value("${spring.profiles.active}") public void setEnv(String activeEnv){ currentActiveEnv = activeEnv; } @PostConstruct private void currentEnvIsDev(){ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateTime = df.format(new Date()); if ("dev".equals(currentActiveEnv)){ currentEnvIsDev = true; System.out.println("【##】"+dateTime + " - 当前环境:【"+currentActiveEnv+"】 - 控制台 打印内容"); }else { System.out.println("【##】"+dateTime + " - 当前环境:【"+currentActiveEnv+"】 - 控制台✖不输出内容"); } } public static void consolePrintIfEnvIsDev(String printContent){ if (currentEnvIsDev){ System.out.println("当前环境:"+currentActiveEnv+" 控制台输出-->>"+printContent); } } }