JAVA——后端Vue动态路由配置类JavaBean封装
生活随笔
收集整理的這篇文章主要介紹了
JAVA——后端Vue动态路由配置类JavaBean封装
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Vue文檔
https://router.vuejs.org/zh/?
源代碼?
package cn.edu.zstu.shihua.xihu.dto;import cn.edu.zstu.shihua.xihu.entity.Menu; import cn.edu.zstu.shihua.xihu.entity.Meta; import cn.edu.zstu.shihua.xihu.model.Resource; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode;/*** @author ShenTuZhiGang* @version 1.0.0* @date 2020-07-26 15:13*/ @Data @EqualsAndHashCode(callSuper = false) @ApiModel(value = "Vue路由配置") public class VueRouteConfig {/*RouteConfig {path: stringname?: stringcomponent?: Componentcomponents?: Dictionary<Component>redirect?: RedirectOptionalias?: string | string[]children?: RouteConfig[]meta?: anybeforeEnter?: NavigationGuardprops?: boolean | Object | RoutePropsFunctioncaseSensitive?: booleanpathToRegexpOptions?: PathToRegexpOptions}*/@ApiModelProperty(name = "路徑",value = "路徑")private String path;@ApiModelProperty(name = "組件",value = "組件")private String component;@ApiModelProperty(name = "名稱",value = "名稱")private String name;@ApiModelProperty(name = "重定向",value = "重定向")private String redirect;@ApiModelProperty(name = "別名",value = "別名")private String alias;@ApiModelProperty(name = "元",value = "元")private Meta meta;@ApiModelProperty(name = "子菜單",value = "子菜單")private List<VueRouteConfig> children; } package cn.edu.zstu.shihua.xihu.entity;import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode;/*** @author ShenTuZhiGang* @version 1.0.0* @date 2020-07-26 14:14*/ @Data @EqualsAndHashCode(callSuper = false) @ApiModel(value = "元") public class Meta {@ApiModelProperty(name = "標題",value = "標題")private String title;@ApiModelProperty(name = "鏈接",value = "鏈接")private String link;@ApiModelProperty(name = "圖標class",value = "圖標class")private String iconClass;@ApiModelProperty(name = "保持",value = "保持")private Boolean keepAlive;@ApiModelProperty(name = "是否需要授權(quán)",value = "是否需要授權(quán)")private Boolean requireAuth; }?
構(gòu)建參考:
?Resource為數(shù)據(jù)庫Model
public static VueRouteConfig build(List<Resource> resources){Map<Integer,Resource> map = new HashMap<>();Map<Integer,List<Integer>> listMap = new HashMap<>();for (Resource resource : resources){map.put(resource.getId(),resource);if(listMap.get(resource.getParentId())==null){listMap.put(resource.getParentId(),new ArrayList<>());}listMap.get(resource.getParentId()).add(resource.getId());}return findChildren(map,listMap,map.get(1));}private static VueRouteConfig findChildren(Map<Integer, Resource> map,Map<Integer,List<Integer>> listMap,Resource resource) {VueRouteConfig vueRouteConfig = new VueRouteConfig();vueRouteConfig.setName(resource.getName());vueRouteConfig.setComponent(resource.getComponent());Meta meta = new Meta();meta.setIconClass(resource.getIconClass());meta.setKeepAlive(resource.getKeepAlive());meta.setRequireAuth(resource.getRequireAuth());vueRouteConfig.setMeta(meta);vueRouteConfig.setPath(resource.getPath());List<VueRouteConfig> vueRouteConfigs = new ArrayList<>();List<Integer> integers = listMap.get(resource.getId());if(integers==null){return vueRouteConfig;}for(Integer id:integers){vueRouteConfigs.add(findChildren(map,listMap,map.get(id)));}vueRouteConfig.setChildren(vueRouteConfigs);return vueRouteConfig;}參考文章
https://blog.csdn.net/frankcheng5143/article/details/52958486
https://blog.csdn.net/frankcheng5143/article/details/72723958
https://www.cnblogs.com/fenghua12/p/5281902.html
總結(jié)
以上是生活随笔為你收集整理的JAVA——后端Vue动态路由配置类JavaBean封装的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Vue——Vue-Router的push
- 下一篇: Spring Security——关闭未