From e172074e153d09fa3b37f64475a520ab8c6a65a1 Mon Sep 17 00:00:00 2001 From: qi_liang Date: Mon, 3 Jun 2019 06:46:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96=EF=BC=8C?= =?UTF-8?q?=E8=A7=A3=E8=80=A6HttpServlerRquest=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lq/cms/service/impl/SysResourceServiceImpl.java | 10 ++++------ src/main/java/com/lq/cms/web/IndexController.java | 7 ++++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/lq/cms/service/impl/SysResourceServiceImpl.java b/src/main/java/com/lq/cms/service/impl/SysResourceServiceImpl.java index 8890bf9..52f5365 100755 --- a/src/main/java/com/lq/cms/service/impl/SysResourceServiceImpl.java +++ b/src/main/java/com/lq/cms/service/impl/SysResourceServiceImpl.java @@ -14,7 +14,6 @@ import com.lq.entity.SysResource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import javax.servlet.http.HttpServletRequest; import java.util.*; import java.util.stream.Stream; @@ -51,7 +50,7 @@ public class SysResourceServiceImpl extends BaseServiceImpl impleme } @Override - public List findMenusListBySysUserId(Long sysUserId, HttpServletRequest request) { + public List findMenusListBySysUserId(Long sysUserId, String contextPath) { Map map=new HashMap(); map.put("userId",sysUserId); map.put("parentId",0L); @@ -71,7 +70,7 @@ public class SysResourceServiceImpl extends BaseServiceImpl impleme menus.setMenuid(sysResource1.getId()); menus.setIcon(sysResource1.getMenuIco()); menus.setMenuname(sysResource1.getMenuName()); - menus.setUrl(request.getContextPath()+sysResource1.getUrlPath()); + menus.setUrl(contextPath+sysResource1.getUrlPath()); menusItem.add(menus); } list.add(menusItem); @@ -80,11 +79,10 @@ public class SysResourceServiceImpl extends BaseServiceImpl impleme } @Override - public List findAllMenusList(HttpServletRequest request) { + public List findAllMenusList(String contextPath) { List sysResourceList = sysResourceDao.findByParentId(0L); Iterator sysResourceIterator = sysResourceList.iterator(); List list=new ArrayList<>(); - Stream resourceStream = sysResourceList.stream(); while (sysResourceIterator.hasNext()){ SysResource sysResource = sysResourceIterator.next(); MenusItem menusItem=new MenusItem(); @@ -99,7 +97,7 @@ public class SysResourceServiceImpl extends BaseServiceImpl impleme menus.setMenuid(nextSysResource.getId()); menus.setIcon(nextSysResource.getMenuIco()); menus.setMenuname(nextSysResource.getMenuName()); - menus.setUrl(request.getContextPath()+nextSysResource.getUrlPath()); + menus.setUrl(contextPath+nextSysResource.getUrlPath()); menusItem.add(menus); } list.add(menusItem); diff --git a/src/main/java/com/lq/cms/web/IndexController.java b/src/main/java/com/lq/cms/web/IndexController.java index c81a8b4..abf7e3e 100755 --- a/src/main/java/com/lq/cms/web/IndexController.java +++ b/src/main/java/com/lq/cms/web/IndexController.java @@ -49,11 +49,12 @@ public class IndexController { Subject subject=SecurityUtils.getSubject(); Session session = subject.getSession(); SysUser sysUser=(SysUser) subject.getPrincipal(); - List list = null; + List list ; + String contextPath = request.getContextPath(); if (subject.hasRole(Constant.ROLE_ADMIN)) { - list = sysResourceService.findAllMenusList(request); + list = sysResourceService.findAllMenusList(contextPath); }else{ - list = sysResourceService.findMenusListBySysUserId(sysUser.getId(), request); + list = sysResourceService.findMenusListBySysUserId(sysUser.getId(), contextPath); } modelAndView.addObject("menusList",list);