1. 程式人生 > 其它 >Web前端(十五)-後臺管理頁面(歡迎XXX登入和退出登入)、釋出作品功能

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方法