Web前端(十五)-后台管理頁面(歡迎XXX登錄和退出登錄)、發布作品功能


后台管理頁面 歡迎xxx和退出登錄

  • 在admin.html頁面中 創建vue對象管理header標簽,並在created里面請求當前登錄的用戶對象,在methods里面聲明logout方法

     <script>
         let header_vm = new Vue({
             el:"header",
             data:{
                 user:{}
            },
             created:function () {
                 //發請求得到當前登錄的用戶對象
                 axios.get("/currentuser").then(function (response) {
                     //代表沒有登錄
                     if (response.data==""){
                         alert("請先登錄!");
                         location.href="/login.html";
                    }
                     header_vm.user = response.data;
                })
            },
             methods: {
                 logout:function () {
                     if (!confirm("您確認退出登錄嗎?")){
                         return;
                    }
                     //發出退出登錄請求
                     axios.get("/logout").then(function () {
                         //顯示到首頁
                         location.href="/index.html";
                    })
                }
            }
        })
     </script>
  • UserController里面處理獲取當前用戶的請求 和 退出登錄請求

  • 在header標簽里面綁定vue相關標簽

 

發布作品功能

  • 建表:

    use vrddb;
     create table product(id int primary key auto_increment,title varchar(50),author varchar(50),url varchar(255),view_count int,like_count int,created timestamp,category_id int)charset=utf8;
     
     alter table product add intro varchar(255) after author;
  • 創建Product實體類

  • 創建ProductMapper 里面提供insert方法

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM