lyq 4 ヶ月 前
コミット
dc2e80f561
1 ファイル変更9 行追加10 行削除
  1. 9 10
      src/main/java/com/sooka/module/web/cms/IndexController.java

+ 9 - 10
src/main/java/com/sooka/module/web/cms/IndexController.java

@@ -95,7 +95,7 @@ public class IndexController {
 
     /*网站首页*/
     @GetMapping
-    public ModelAndView index(@RequestParam(value = "keyword",required = false) String keyword, HttpServletRequest request){
+    public ModelAndView index(@RequestParam(value = "keyword",required = false) String keyword){
         String domain = ControllerUtil.getDomain();
         log.debug("通过域名访问网站首页[{}]",domain);
         TCmsSite site = siteService.findByDomain(domain);
@@ -105,13 +105,7 @@ public class IndexController {
         if(!StrUtil.isBlank(keyword)) {
             return new ModelAndView( "forward:/"+sitePrefix+"/search");
         }
-        ModelAndView modelAndView = new ModelAndView( "forward:/"+sitePrefix+"/"+site.getSiteId());
-        if (request.getSession().getAttribute(LOGIN_USER) == null) {
-            modelAndView.addObject("btnId", "login");
-        } else {
-            modelAndView.addObject("btnId", "exit");
-        }
-        return modelAndView;
+        return new ModelAndView( "forward:/"+sitePrefix+"/"+site.getSiteId());
     }
 
     @GetMapping("/login")
@@ -124,7 +118,7 @@ public class IndexController {
     @GetMapping("/exit")
     public ModelAndView exit(HttpServletRequest request){
         request.getSession().removeAttribute(LOGIN_USER);
-        return index(null, request);
+        return index(null);
     }
 
     @GetMapping("/register")
@@ -180,7 +174,7 @@ public class IndexController {
      */
     @GetMapping("/${system.site.prefix}/{siteId}")
     public String index(@PathVariable("siteId") Integer siteId,
-                        Model model){
+                        Model model,HttpServletRequest request){
         log.debug("通过站点Id访问网站首页[{}]",siteId);
         SimpleDateFormat formatYear = new SimpleDateFormat("yyyy");
         SimpleDateFormat format = new SimpleDateFormat("yyyy-M-d");
@@ -213,6 +207,11 @@ public class IndexController {
         model.addAttribute("description",site.getDescription());
         model.addAttribute("site",site);
         model.addAttribute("xwdtList",xwdtList);
+        if (request.getSession().getAttribute(LOGIN_USER) == null) {
+            model.addAttribute("btnId", "login");
+        } else {
+            model.addAttribute("btnId", "exit");
+        }
         if(StrUtil.isBlank(site.getTemplate())) {
             return view(CmsConst.INDEX_TPL);
         }