diff --git a/springboot-ademo/src/main/java/com/tiesheng/demo/DemoApplication.java b/springboot-ademo/src/main/java/com/tiesheng/demo/DemoApplication.java index 1efeb5d..df49a63 100644 --- a/springboot-ademo/src/main/java/com/tiesheng/demo/DemoApplication.java +++ b/springboot-ademo/src/main/java/com/tiesheng/demo/DemoApplication.java @@ -14,7 +14,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @EnableTransactionManagement @SpringBootApplication @EnableTieshengWeb(webConfigurer = DemoWebConfigurer.class) -@EnableEncryptConfig +//@EnableEncryptConfig public class DemoApplication { public static void main(String[] args) { diff --git a/springboot-ademo/src/main/java/com/tiesheng/demo/controller/TestController.java b/springboot-ademo/src/main/java/com/tiesheng/demo/controller/TestController.java index 3ff37da..4add719 100644 --- a/springboot-ademo/src/main/java/com/tiesheng/demo/controller/TestController.java +++ b/springboot-ademo/src/main/java/com/tiesheng/demo/controller/TestController.java @@ -53,7 +53,7 @@ public class TestController { @TokenIgnore public void redirect(HttpServletResponse response) { // tsTokenConfig.validToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NzYwMDY4NzUsImlkIjoiMSIsImVudmlyb25tZW50VHlwZSI6Im1vYmlsZSIsInNlcnZpY2UiOiJjb250ZXN0LXJlc2VydmUiLCJleHRyYSI6IiJ9.nsfxEFpCNHC7eNCS5DJXdu1VDdnHrTjSfgrozND70Lc", true); -// globalConfig.redirect("mobile", "/test", response); + globalConfig.redirect("mobile", "/test", response); } diff --git a/springboot-ademo/src/main/resources/application-test.yml b/springboot-ademo/src/main/resources/application-test.yml index 9a556e3..de8acba 100644 --- a/springboot-ademo/src/main/resources/application-test.yml +++ b/springboot-ademo/src/main/resources/application-test.yml @@ -21,7 +21,7 @@ tiesheng: id: "1111" global: version: 2 - host: http://localhost:8080 + host: http://localhost:8100 aliyun: access-key-id: LTAI5tJtbgBCnTY5eS4SmrTf access-key-secret: JIHqpRUFffCHhXaJEVvWN31WcexWqG diff --git a/springboot-ademo/src/main/resources/static/mobile/v1.0.0/index.html b/springboot-ademo/src/main/resources/static/mobile/0.0.13/index.html similarity index 100% rename from springboot-ademo/src/main/resources/static/mobile/v1.0.0/index.html rename to springboot-ademo/src/main/resources/static/mobile/0.0.13/index.html diff --git a/springboot-ademo/src/main/resources/static/mobile/v1.0.1/index.html b/springboot-ademo/src/main/resources/static/mobile/0.0.4/index.html similarity index 100% rename from springboot-ademo/src/main/resources/static/mobile/v1.0.1/index.html rename to springboot-ademo/src/main/resources/static/mobile/0.0.4/index.html diff --git a/springboot-util/src/main/java/com/tiesheng/util/config/GlobalConfig.java b/springboot-util/src/main/java/com/tiesheng/util/config/GlobalConfig.java index 36fda2e..85a7bf6 100644 --- a/springboot-util/src/main/java/com/tiesheng/util/config/GlobalConfig.java +++ b/springboot-util/src/main/java/com/tiesheng/util/config/GlobalConfig.java @@ -1,5 +1,7 @@ package com.tiesheng.util.config; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.comparator.VersionComparator; import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; @@ -12,6 +14,8 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; /** * @author hao @@ -62,15 +66,22 @@ public class GlobalConfig { * @param route */ public void redirect(String htmlDir, String route, HttpServletResponse response) { + if (!StrUtil.endWith(htmlDir, "/")) { + htmlDir = htmlDir + "/"; + } PathMatchingResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver(); try { Resource[] resources = patternResolver.getResources(String.format("classpath*:static/%s/*/index.html", htmlDir)); - if (resources.length == 0) { + List versions = new ArrayList<>(); + for (Resource resource : resources) { + String path = FileUtil.normalize(resource.getURL().getPath()); + versions.add(StrUtil.subBetween(path, htmlDir, "/index.html")); + } + if (CollUtil.isEmpty(versions)) { throw new ApiException("无法重定向,请检查资源"); } - String filename = resources[resources.length - 1].getURL().getPath(); - filename = FileUtil.normalize(filename); - String path = buildPath(String.format("/%s%s#%s", htmlDir, StrUtil.subAfter(filename, htmlDir, true), route)); + CollUtil.sort(versions, (o1, o2) -> -VersionComparator.INSTANCE.compare(o1, o2)); + String path = buildPath(String.format("/%s%s/index.html#%s", htmlDir, versions.get(0), route)); response.sendRedirect(path); } catch (IOException e) { LogFactory.get().info(e);