Web前端(十五)-后台管理页面(欢迎XXX登录和退出登录)、发布作品功能

时间:2021-08-12
本文章向大家介绍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方法

 

原文地址:https://www.cnblogs.com/XiaoCui-blog/p/15134384.html