diff --git a/src/main/resources/modules/SpringBoot/java/action/GlobalController.ftl b/src/main/resources/modules/SpringBoot/java/action/GlobalController.ftl index de0a88c0..00d015ad 100644 --- a/src/main/resources/modules/SpringBoot/java/action/GlobalController.ftl +++ b/src/main/resources/modules/SpringBoot/java/action/GlobalController.ftl @@ -88,21 +88,24 @@ public class GlobalController implements ErrorController { } } + @RequestMapping("/") + public String home(HttpServletRequest request) { + String contextPath = request.getContextPath(); + return "forward:" + contextPath+ homePage; + } + /** * 当未明确指定控制器时,走该请求,默认返回对应的layout布局和screen视图 * 当需要使用layout时,不需要返回值,ViewNameTranslator会处理对应关系 * @param model * @param request */ - @RequestMapping({"/**.htm", "/"}) + @RequestMapping({"/**.htm"}) public void hold(HttpServletRequest request, Model model) { HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse(); // 处理根Url String servletPath = request.getServletPath(); - if ("/".equals(servletPath)) { - servletPath = "/" + homePage; - } if (servletPath.matches("(.+)\\.htm")) { Pattern compile = Pattern.compile("(.+)\\.htm"); Matcher matcher = compile.matcher(servletPath); diff --git a/src/main/resources/modules/SpringBoot/java/config/BeanDefinitionRegistryConfig.java b/src/main/resources/modules/SpringBoot/java/config/BeanDefinitionRegistryConfig.java index 07aa8645..422cd5f5 100644 --- a/src/main/resources/modules/SpringBoot/java/config/BeanDefinitionRegistryConfig.java +++ b/src/main/resources/modules/SpringBoot/java/config/BeanDefinitionRegistryConfig.java @@ -24,8 +24,8 @@ public class BeanDefinitionRegistryConfig implements BeanDefinitionRegistryPostP @Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException { String aPackage = this.getClass().getPackage().getName(); - int i = registryScreen(aPackage.replaceAll("framework.config", "action.screen"), beanDefinitionRegistry); - int i1 = registryControl(aPackage.replaceAll("framework.config", "action.control"), beanDefinitionRegistry); + int i = registryScreen("${basePackage}.action.screen", beanDefinitionRegistry); + int i1 = registryControl("${basePackage}.action.control", beanDefinitionRegistry); System.out.println(); } diff --git a/src/main/resources/modules/SpringBoot/java/frame/freemarker/Layout.java b/src/main/resources/modules/SpringBoot/java/frame/freemarker/Layout.java index a564bea9..b35e6bc4 100644 --- a/src/main/resources/modules/SpringBoot/java/frame/freemarker/Layout.java +++ b/src/main/resources/modules/SpringBoot/java/frame/freemarker/Layout.java @@ -5,7 +5,6 @@ import ${basePackage}.config.BeanDefinitionRegistryConfig; import freemarker.template.TemplateModelException; import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.validation.support.BindingAwareModelMap; import org.springframework.web.context.request.RequestContextHolder; @@ -30,9 +29,6 @@ import ${basePackage}.frame.utils.LocalData; @Component public class Layout { - @Value("${r"${web.welcome.page}"}") - private String homePage; - @Autowired private FreeMarkerViewResolver viewResolver; @@ -44,15 +40,9 @@ public class Layout { try { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); LocaleResolver localeResolver = (LocaleResolver) request.getAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE); - String servletPath = request.getServletPath(); - if ("/".equals(servletPath)) { - servletPath = this.homePage; - } - if (servletPath.startsWith("/")) { - servletPath = servletPath.substring(1); - } + String servletPath = LocalData.getTarget(); + servletPath = servletPath.replaceAll("^/", ""); - // 去除头部/ String[] split = servletPath.split("/"); StringBuilder sb = new StringBuilder(""); diff --git a/src/main/resources/modules/SpringBoot/java/frame/freemarker/ViewNameTranslator.java b/src/main/resources/modules/SpringBoot/java/frame/freemarker/ViewNameTranslator.java index 040692f5..d802e806 100644 --- a/src/main/resources/modules/SpringBoot/java/frame/freemarker/ViewNameTranslator.java +++ b/src/main/resources/modules/SpringBoot/java/frame/freemarker/ViewNameTranslator.java @@ -2,7 +2,6 @@ package ${basePackage}.frame.freemarker; import ${basePackage}.frame.utils.LocalData; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.LocaleResolver; @@ -25,9 +24,6 @@ import java.util.Map; @Component("viewNameTranslator") public class ViewNameTranslator extends DefaultRequestToViewNameTranslator { - @Value("${r"${web.welcome.page}"}") - private String homePage; - @Autowired private FreeMarkerViewResolver viewResolver; @Autowired @@ -49,11 +45,7 @@ public class ViewNameTranslator extends DefaultRequestToViewNameTranslator { try { LocaleResolver localeResolver = (LocaleResolver) request.getAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE); String servletPath = LocalData.getTarget(); - if (servletPath != null && "/".equals(servletPath)) { - servletPath = homePage; - } else { - servletPath = servletPath.replaceAll("^/", ""); - } + servletPath = servletPath.replaceAll("^/", ""); Locale locale = localeResolver.resolveLocale(request); {//查询screen diff --git a/src/main/resources/modules/SpringBoot/resources/application-dev.ftl b/src/main/resources/modules/SpringBoot/resources/application-dev.ftl index 4b9218bf..9713a8e7 100644 --- a/src/main/resources/modules/SpringBoot/resources/application-dev.ftl +++ b/src/main/resources/modules/SpringBoot/resources/application-dev.ftl @@ -13,7 +13,7 @@ spring.http.encoding.charset=UTF-8 spring.http.encoding.enabled=true server.tomcat.uri-encoding=UTF-8 # 根路径、欢迎页 -web.welcome.page = index.htm +web.welcome.page = /index.htm # 需要验证授权 web.url.auth.included = /** # 不需要验证授权 diff --git a/src/main/resources/modules/SpringBoot/resources/application-prod.ftl b/src/main/resources/modules/SpringBoot/resources/application-prod.ftl index 270fe5bd..27e0d6a4 100644 --- a/src/main/resources/modules/SpringBoot/resources/application-prod.ftl +++ b/src/main/resources/modules/SpringBoot/resources/application-prod.ftl @@ -14,7 +14,7 @@ spring.http.encoding.charset=UTF-8 spring.http.encoding.enabled=true server.tomcat.uri-encoding=UTF-8 # 根路径、欢迎页 -web.welcome.page = index.htm +web.welcome.page = /index.htm # 需要验证授权 web.url.auth.included = /** # 不需要验证授权