最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

bootstrap+spring boot實(shí)現(xiàn)面包屑導(dǎo)航功能(前端代碼)

 更新時(shí)間:2019年10月09日 09:30:25   作者:羅漢爺  
這篇文章主要介紹了bootstrap+spring boot實(shí)現(xiàn)面包屑導(dǎo)航,在cms建站時(shí)都會(huì)有這種面包屑導(dǎo)航功能,文中給出了前端實(shí)例代碼,需要的朋友可以參考下

面包屑導(dǎo)航介紹

一般的內(nèi)容型網(wǎng)站,例如CMS都會(huì)有這種面包屑導(dǎo)航??偨Y(jié)起來它有以下優(yōu)勢(shì):

讓用戶了解目前所在的位置,以及當(dāng)前頁(yè)面在整個(gè)網(wǎng)站中所在的位置;

體現(xiàn)了網(wǎng)站的架構(gòu)層級(jí);提高了用戶體驗(yàn);

減少返回到上一級(jí)頁(yè)面的操作;

實(shí)現(xiàn)效果

那我們應(yīng)該如何實(shí)現(xiàn)?我看網(wǎng)上多數(shù)都是只提供靜態(tài)實(shí)現(xiàn),

這里我結(jié)合bootstrap 和 spring boot以及mysql來做一個(gè)完整的例子。

表結(jié)構(gòu)設(shè)計(jì)

圖里面的菜單其實(shí)是分級(jí)維護(hù)上下級(jí)關(guān)系的。我這里用到了2級(jí),表里有l(wèi)evel字段標(biāo)記。

點(diǎn)擊第1級(jí)加載第2級(jí)分類,點(diǎn)擊第2級(jí)分類名稱則展示面包屑導(dǎo)航。

CREATE TABLE `tb_category` (
 `id` bigint(20) NOT NULL AUTO_INCREMENT,
 `category_name` varchar(100) NOT NULL,
 `parent_id` bigint(20) DEFAULT NULL,
 `level` tinyint(1) DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;
insert into tb_category values(1,'Java文檔',0,1);
insert into tb_category values(2,'Java多線程',1,2);
insert into tb_category values(3,'Spring Boot',1,2);
insert into tb_category values(4,'微服務(wù)實(shí)戰(zhàn)',1,2);
insert into tb_category values(5,'Java視頻',0,1);
insert into tb_category values(6,'Java基礎(chǔ)',5,2);
insert into tb_category values(7,'Java基礎(chǔ)',1,2);
commit;

前端代碼

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
   xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>響應(yīng)式布局</title>
  <link  rel="stylesheet">
</head>
<body>
<input type="text" id="ctx" hidden="hidden" th:value="${#request.getContextPath()}">
<div class="container-fluid">
  <!--頁(yè)頭-->
  <nav class="navbar navbar-inverse">
    <div class="container-fluid">
      <!-- Brand and toggle get grouped for better mobile display -->
      <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
            data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" th:href="@{'/breadCrumb'}" rel="external nofollow" >Java分享</a>
      </div>
      <!-- Collect the nav links, forms, and other content for toggling -->
      <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <ul class="nav navbar-nav" id="navbar">
        </ul>
      </div>
    </div>
  </nav>
  <!--面包屑-->
  <ol class="breadcrumb">
  </ol>
  <div class="list-group" id="submenu-list">
  </div>
</div>
<script src="https://cdn.bootcss.com/jquery/3.4.0/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
  var ctx=$("#ctx").val();
  $(function () {
    // 獲取一級(jí)菜單
    getMenu(null,1);
  });
  function getMenu(id, level){
    var json = {parentId:id,level:level};
    $.ajax({
      url: ctx+"/myCategory/list",
      type: "POST",
      contentType: "application/json",
      dataType: "json",
      data: JSON.stringify(json),
      success: function (result) {
        var text='';
        if (result.success) {
          if(result.data != null){
            // 一級(jí)菜單
            if(level!=null){
              $.each(result.data, function (i, r) {
                text += '<li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" οnclick="getMenu('+r.id+')">'+r.categoryName+'</a></li>'
              });
              $("#navbar").empty();
              $("#navbar").append(text);
            }
            // 子菜單
            if(id!=null){
              $.each(result.data, function (i, r) {
                console.log(i);
                text += '<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="list-group-item" οnclick="getBreadCrumb('+r.id+')">'+r.categoryName+'</a>'
              });
              $("#submenu-list").empty();
              $("#submenu-list").append(text);
            }
          }
        } else {
          alert(result.message);
        }
      }
    });
  }
  // 生成面包屑導(dǎo)航
  function getBreadCrumb(id) {
    var param = {id:id};
    $.ajax({
      url: ctx+"/myCategory/getParentList",
      type: "GET",
      data: {"id":id},
      success: function (result) {
        var text='';
        if(result.data!=null){
          text = '<li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首頁(yè)</a></li>';
          $.each(result.data, function (i, r) {
            text += '<li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >'+r.categoryName+'</a></li>'
          });
          $(".breadcrumb").empty();
          $(".breadcrumb").append(text);
        }
      }
    })
  }
</script>
</body>
</html>

總結(jié)

以上所述是小編給大家介紹的bootstrap+spring boot實(shí)現(xiàn)面包屑導(dǎo)航功能,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

相關(guān)文章

最新評(píng)論

泸水县| 台中县| 台安县| 衡东县| 镇江市| 峡江县| 宜州市| 英山县| 新宁县| 遵义市| 康定县| 江安县| 安陆市| 德清县| 新源县| 武川县| 西乌珠穆沁旗| 辽阳县| 三门峡市| 石狮市| 涞源县| 郎溪县| 车致| 临武县| 平湖市| 盐津县| 寿阳县| 沁阳市| 广南县| 呼图壁县| 玉树县| 定西市| 五台县| 农安县| 德安县| 襄城县| 孟州市| 蓬莱市| 太保市| 抚州市| 梁平县|