首頁>技術>

商家許可權及其選單資源管理設計

在商家的選單體系中,我們設計了一個三級選單,分別為分類、模組和資源。其中,分類選單是頂級選單,表示一個微服務應用;模組選單是一個二級選單,表示一個應用功能(實體)的主頁;資源選單是三級選單,表示一個實體的增刪改查中某一個具體的操作的許可權。

在平臺管理後臺中,必須對這些選單進行統一管理。下面就對各個選單的管理及其設計分別加以說明。

分類選單管理設計

分類選單是一個頂級選單,它所連線的是一個Web微服務應用,如庫存管理、訂單管理等,所以頂級菜單隻在SSO首頁中進行展示。

在分類選單中管理包括增刪改查等操作內容,下面以分類選單查詢的設計為例進行說明。首先使用控制器設計MerchantKindController,透過呼叫商家服務KindRestService取得分類選單資料;然後將查詢結果轉換為檢視輸出,即返回 show.html的檢視設計,實現程式碼如下所示:

@Controller@RequestMapping("/merchantkind")public class MerchantKindController {private static Logger logger =LoggerFactory.getLogger (MerchantKindController.class);@Autowiredprivate KindRestService kindRestService;CRequestMapping(value="/{id} ")public String show(ModelMap model, @PathVariable Long id) {String json = kindRestService.findById(id);model.addAttribute ("kind",new Gson ().fromJson(json, KindQo.class));return "merchantkind/show";}}

在show.html 的檢視設計中,透過對話方塊的方式顯示了show.html 的頁面內容。其中,頁面設計部分的實現程式碼如下所示:

圖11-3所顯示的內容是一個“訂單系統”的分類選單的查詢資訊,其中“連結服務”使用的是訂單微服務應用的例項名稱。當操作者開啟使用微服務名稱作為頂級選單的連結時,將透過服務名稱找到相應的連結地址再進行訪問。

模組選單管理設計

模組選單是商家管理後臺的一個二級選單,它表示一個應用中的一個業務型別。例如,在頂級選單“訂單系統”中可以包含“訂單管理”和“訂單報表”等模組選單。

在模組選單中包括選單的增刪改查等操作內容,下面以新建模組選單的設計為例進行說明。

如下所示是一個新建模組選單的控制器MerchantModelController 的設計:

@Controller@RequestMapping ("/merchantmodel")public class MerchantModelController {private static Logger logger =LoggerFactory.getLogger (MerchantModelController.class);@Autowiredprivate KindRestService kindRestService;@Autowiredprivate ModelRestService modelRestService;@RequestMapping( "/new")public String create (ModelMap model,HttpServletRequest request){String json = kindRestService.findList();List<KindQo> kindQos = new Gson() .fromJson(json,newTypeToken<List<KindQ0>>() {-getType());//快取模組列表request.getSession().setAttribute ("kinds",kindQos);model. addAttribute("kinds", kindQ0s);return "merchantmodel/new";}@RequestMapping(value="/save", method = RequestMethod.POST)@ResponseBodypublic String save (Mode1Qo modelQo,HttpServletRequest request) throwsException {//透過模組工D指定關聯物件String kid = request.getParameter ( "kid");//獲取模組列表List<KindQ0> kindQos =(List<KindQ0>)request.getsession().getAttribute("kinds");for(KindQo kindQo : kindQos){if (kindQo.getId() .compareTo (new Long (kid)) == 0){modelQ0. setKind(kindQo);break;}}String ret = modelRestService.create (modelQ0);logger.info("新增=”+ret);return ret;}}

需要注意的是,這裡使用了查詢物件ModelQo來獲取表單的引數。這與使用實體物件來獲

取引數略有不同,即使用查詢物件不能得到所天聯的對家,所以垃裡史n組相對負,而不基示模組所關聯的分類物件的ID,然後從我們在會話中儲存的物件列表中取得相關物件,而不是

使用kid這樣的引數直接取得所關聯的分類物件。

在相關頁面的檢視設計上,也必須要有與之對應的設計。如下所示是一個新建模組選單的檢視new.html的設計:

在完成設計後,模組選單管理的顯示效果如圖11-4所示。

在圖11-4中,URL是進入訂單管理主頁的一個連結地址,選單所關聯的上級選單為“訂單系統”。從這個設計中可以看出,二級的連結地址是一個應用的主頁。

資源選單管理設計

在資源選單中包括增刪改查等操作內容,下面以資源編輯的設計為例進行說明。

資源編輯控制器 MerchantResourceController的設計部分的程式碼如下所示:

@Controller@RequestMapping("/merchantresource")public class MerchantResourceController{private static Logger logger =LoggerFactory.getLogger (MerchantResourceController.class);@Autowiredprivate ResourceRestService resourceRestService;@Autowiredprivate ModelRestService modelRestService;@RequestMapping ("/index")public string index (ModelMap model,Principal user) throws Exception"model .addAttribute( "user",user);return "merchantresource/index";@RequestMapping("/edit/{id} ")public String edit(@PathVariable Long id,ModelMap model, HttpServletRequestrequest) {String json = resourceRestService.findById(id);ResourceQo resourceQo = new Gson().fromJson(json,ResourceQo.classString models - modelRestService.findList();List<ModelQo> modelQoList = new Gson().fromJson(models,newTypeToken<List<ModelQ0>>() {].getType();//快取模組列表request.getSession().setAttribute ("models",modelQoList);model .addAttribute( "models",modelQoList);model.addAttribute("resource", resourceQ0);return "merchantresource/edit";}@RequestMapping (method = RequestMethod. POST, value="/update")@ResponseBodypublic String update(ResourceQo resourceQo,HttpServletRequest requestthrows Exception{//透過模組ID指定關聯物件String mid - request.getParameter ( "mid");//獲取模組列表List<ModelQo> modelQos = (List<ModelQ0>)request.getSession() .getAttribute ( "models");for(ModelQo modelQ0 : modelQos){if (modelQo.getId().compareTo(new Long (mid)) ==0){resourceQo .setModel (modelQ0);break;}}String ret = resourceRestService.update(resourceQ0);logger.info(”修改="+ret);return ret;}}

在進行資源編輯之前,首先取出模組列表,並使用這個模組列表在頁面中設計一個下拉框。然後在資源編輯時從這個下拉框中選擇一個模組設定它的上級選單。最後在資料儲存時,透過模組D取出相應的物件進行儲存。

其對應的頁面檢視edit.html的設計如下所示:

從圖11-5中可以看出,三級選單是在一個應用中對某一個實體進行增刪改查時的一項操作許可權,URL是一個執行訂單修改的連結地址。在連結地址後面增加的幾個符號“/**”是為了方便許可權的檢查,也可以省略不用,而所關聯的模組選單“訂單管理”就是訂單修改的上級選單。

17
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • JavaScript 25 歲了