日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

JAVA——后端Vue动态路由配置类JavaBean封装

發布時間:2024/10/5 vue 72 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JAVA——后端Vue动态路由配置类JavaBean封装 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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 = "是否需要授權",value = "是否需要授權")private Boolean requireAuth; }

?

構建參考:

?Resource為數據庫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

總結

以上是生活随笔為你收集整理的JAVA——后端Vue动态路由配置类JavaBean封装的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。