111.【金橘社区1.0】(三)

简介: 111.【金橘社区1.0】
(2).后端页面
package com.jsxs.kumquat.controller;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jsxs.kumquat.pojo.CkqnBlog;
import com.jsxs.kumquat.pojo.CkqnUser;
import com.jsxs.kumquat.service.CkqnBlogService;
import com.jsxs.kumquat.utils.FileUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.UUID;
/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 吉士先生
 * @since 2023-04-09
 */
@Controller
@RequestMapping("/article")
public class CkqnBlogController {
    @Resource
    CkqnBlogService ckqnBlogService;
    @Resource
    HttpSession session;
    // 文章上传
    @RequestMapping("/publish")
    public String publishArticle(CkqnBlog article) {
        CkqnUser user = (CkqnUser) session.getAttribute("loginUser");
        // 1.作者信息
        article.setAuthorId(user.getUid());
        article.setAuthorName(user.getUsername());
        article.setAuthorAvatar(user.getAvatar());
        // 2.博客ID
        String replace = UUID.randomUUID().toString().replace("-", "");
        article.setBid(replace);
        if (article.getTitle() == null) {
            System.out.println("标题为空?????????");
        }
        boolean res = ckqnBlogService.save(article);
        if (res) {
            return "tipSuccess";
        }
        return "tipFalse";
    }
    // 文件上传
    @RequestMapping("/image/upload")
    @ResponseBody
    public JSONObject imageUpload(@RequestParam("editormd-image-file") MultipartFile image) {
        JSONObject jsonObject = new JSONObject();
        if (image != null) {
            String path = FileUtils.uploadFile(image);
//            回调给 editor
            System.out.println(path);
            jsonObject.put("url", path);
            jsonObject.put("success", 1);
            jsonObject.put("message", "upload success!");
            return jsonObject;
        }
        jsonObject.put("success", 0);
        jsonObject.put("message", "upload error!");
        return jsonObject;
    }
    //  1.一篇详细文章
    @RequestMapping("/get/{id}")
    public ModelAndView getArticleById(@PathVariable(name = "id") int id) {
        ModelAndView modelAndView = new ModelAndView();
        CkqnBlog article = ckqnBlogService.getById(id);
        modelAndView.setViewName("WriteCenter/article");
        if (article == null) {
            modelAndView.addObject("article", new CkqnBlog());
        }
        modelAndView.addObject("article", article);
        return modelAndView;
    }
    // 开始修改
    @RequestMapping("/update/editor/{authorId}/{bid}")
    public String updateArticleByUser(@PathVariable("authorId") String authorId, @PathVariable("bid") String bid, Model model) {
//        CkqnUser user = (CkqnUser)session.getAttribute("loginUser");
        QueryWrapper<CkqnBlog> wrapper = new QueryWrapper<>();
        //  查询uid
        CkqnBlog blog = ckqnBlogService.getOne(wrapper.eq("bid", bid));
        System.out.println(authorId + " " + bid);
        // 2.查询作者
        if (!blog.getAuthorId().equals(authorId)) {
            System.out.println("对不起,你在非法编辑");
            //  直接注销账号
            return "redirect:/index.html";
        }
        // 3. 存放文章
        model.addAttribute("blog", blog);
        //  4.没有重定向
        return "WriteCenter/update";
    }
    //    修改的操作
    @PostMapping("/toupdate")
    public String editor(CkqnBlog blog) {
        QueryWrapper<CkqnBlog> wrapper = new QueryWrapper<>();
        System.out.println(blog);
        CkqnBlog queryBlog = ckqnBlogService.getOne(wrapper.eq("bid", blog.getBid()));
        queryBlog.setTitle(blog.getTitle());
        queryBlog.setCategoryId(blog.getCategoryId());
        queryBlog.setContent(blog.getContent());
        boolean b = ckqnBlogService.updateById(queryBlog);
        if (b) {
            return "tipSuccess";
        }
        return "tipFalse";
    }
}

3.文章展示

(1).前端页面
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
    <meta charset="UTF-8">
    <title>金橘社区-文章展示</title>
    <link rel="stylesheet" th:href="@{/editor.md/css/examples/style.css}" />
    <link rel="stylesheet" th:href="@{/editor.md/css/editormd.css}" />
    <link rel="shortcut icon" href="https://pandao.github.io/editor.md/favicon.ico" type="image/x-icon" />
    <script th:src="@{/Jquery/jquery-3.6.1.js}"></script>
    <link rel="stylesheet" th:href="@{/css/commons.css}">
    <link rel="stylesheet" th:href="@{/css/blog_detail.css}">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <style>
        .arrow{
            border: 9px solid transparent;
            border-bottom-color: #3DA0DB;
            width: 0px;
            height: 0px;
            top:0px
        }
        .stick{
            width: 8px;
            height: 14px;
            border-radius: 1px;
            background-color: #3DA0DB;
            top:15px;
        }
        #back_top div{
            position: absolute;
            margin: auto;
            right: 0px;
            left: 0px;
        }
        #back_top{
            background-color: #dddddd;
            height: 38px;
            width: 38px;
            border-radius: 3px;
            display: block;
            cursor: pointer;
            position: fixed;
            right: 50px;
            bottom: 100px;
            display: none;
        }
    </style>
</head>
<body>
<div class="top-search" style="margin-top: 12px;">
    <a type="button" class="layui-btn layui-btn-primary1 layui-btn-lg" style="margin-top: 42px;margin-left: 1px;"
           th:href="@{/MyArticals.html}" ><i class="layui-icon layui-icon-return"
                                                                  style="font-size: 20px; color: #1E9FFF;"></i><i
            style="color: #0e0c0d;font-family: 微软雅黑;font-weight: bold">文章管理</i></a>
</div>
<span class="js-cursor-container"></span>
<div id="article"></div>
<div id="back_top">
    <div class="arrow"></div>
    <div class="stick"></div>
</div>
<!-- .container 作为页面的版心 -->
<div class="container">
    <!-- 左侧个人信息 -->
    <div class="left">
        <!-- 整个用户信息区 -->
        <div class="card">
            <img  th:src="@{/img/login.png}" alt="">
            <h3 th:text="${article.getAuthorName()}"></h3>
            <a href="#">github 地址</a>
            <div class="counter">
                <span>文章</span>
                <span>分类</span>
            </div>
            <div class="counter">
                <span>X</span>
                <span>X</span>
            </div>
        </div>
    </div>
    <!-- 右侧内容详情 -->
    <div class="right" style="overflow: auto">
        <!-- 包裹整个博客的内容详情 -->
        <div class="blog-content">
            <h3 style="color: #e8136f" th:text="${article.title}"></h3>
            <div class="date" th:text="${#dates.format(article.getGmtCreate(),'yyyy-MM-dd HH:mm:ss')}"></div>
<!--            <h2 style="align-content: center" th:text="${article.authorName}"></h2>-->
    <div id="layout">
    <div id="test-editormd">
                <textarea style="display:none;" th:text="${article.content}"></textarea>
    </div>
</div>
</div>
</div>
</div>
<script th:src="@{/editor.md/examples/js/jquery.min.js}"></script>
<script th:src="@{/editor.md/lib/marked.min.js}"></script>
<script th:src="@{/editor.md/lib/prettify.min.js}"></script>
<script th:src="@{/editor.md/lib/raphael.min.js}"></script>
<script th:src="@{/editor.md/lib/underscore.min.js}"></script>
<script th:src="@{/editor.md/lib/sequence-diagram.min.js}"></script>
<script th:src="@{/editor.md/lib/flowchart.min.js}"></script>
<script th:src="@{/editor.md/lib/jquery.flowchart.min.js}"></script>
<script th:src="@{/editor.md/editormd.js}"></script>
<script type="text/javascript">
    var testEditor;
    $(function () {
        testEditor = editormd.markdownToHTML("test-editormd", {
            width: "90%",
            height: 700,
            path: "/editor.md/lib/",
            preview: true,
            watch: true,
            editor: false,
        })
    })
    ! function (e, t, a) {
        function r() {
            for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[
                e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x +
                "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e]
                    .scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");
            requestAnimationFrame(r)
        }
        function n() {
            var t = "function" == typeof e.onclick && e.onclick;
            e.onclick = function (e) {
                t && t(), o(e)
            }
        }
        function o(e) {
            var a = t.createElement("div");
            a.className = "heart", s.push({
                el: a,
                x: e.clientX - 5,
                y: e.clientY - 5,
                scale: 1,
                alpha: 1,
                color: c()
            }), t.body.appendChild(a)
        }
        function i(e) {
            var a = t.createElement("style");
            a.type = "text/css";
            try {
                a.appendChild(t.createTextNode(e))
            } catch (t) {
                a.styleSheet.cssText = e
            }
            t.getElementsByTagName("head")[0].appendChild(a)
        }
        function c() {
            return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math
                .random()) + ")"
        }
        var s = [];
        e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e
            .mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {
            setTimeout(e, 1e3 / 60)
        }, i(
            ".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"
        ), n(), r()
    }(window, document);
    //-----------------------------
    (function fairyDustCursor() {
        var possibleColors = ["#D61C59", "#E7D84B", "#1B8798"]
        var width = window.innerWidth;
        var height = window.innerHeight;
        var cursor = { x: width / 2, y: width / 2 };
        var particles = [];
        function init() {
            bindEvents();
            loop();
        }
        // Bind events that are needed
        function bindEvents() {
            document.addEventListener('mousemove', onMouseMove);
            window.addEventListener('resize', onWindowResize);
        }
        function onWindowResize(e) {
            width = window.innerWidth;
            height = window.innerHeight;
        }
        function onMouseMove(e) {
            cursor.x = e.clientX;
            cursor.y = e.clientY;
            addParticle(cursor.x, cursor.y, possibleColors[Math.floor(Math.random() * possibleColors.length)]);
        }
        function addParticle(x, y, color) {
            var particle = new Particle();
            particle.init(x, y, color);
            particles.push(particle);
        }
        function updateParticles() {
            // Updated
            for (var i = 0; i < particles.length; i++) {
                particles[i].update();
            }
            // Remove dead particles
            for (var i = particles.length - 1; i >= 0; i--) {
                if (particles[i].lifeSpan < 0) {
                    particles[i].die();
                    particles.splice(i, 1);
                }
            }
        }
        function loop() {
            requestAnimationFrame(loop);
            updateParticles();
        }
        /**
         * Particles
         */
        function Particle() {
            this.character = "*";
            this.lifeSpan = 120; //ms
            this.initialStyles = {
                "position": "fixed",
                "display": "inline-block",
                "top": "0px",
                "left": "0px",
                "pointerEvents": "none",
                "touch-action": "none",
                "z-index": "10000000",
                "fontSize": "25px",
                "will-change": "transform"
            };
            // Init, and set properties
            this.init = function (x, y, color) {
                this.velocity = {
                    x: (Math.random() < 0.5 ? -1 : 1) * (Math.random() / 2),
                    y: 1
                };
                this.position = { x: x + 10, y: y + 10 };
                this.initialStyles.color = color;
                this.element = document.createElement('span');
                this.element.innerHTML = this.character;
                applyProperties(this.element, this.initialStyles);
                this.update();
                document.querySelector('.js-cursor-container').appendChild(this.element);
            };
            this.update = function () {
                this.position.x += this.velocity.x;
                this.position.y += this.velocity.y;
                this.lifeSpan--;
                this.element.style.transform = "translate3d(" + this.position.x + "px," + this.position.y + "px, 0) scale(" + (this.lifeSpan / 120) + ")";
            }
            this.die = function () {
                this.element.parentNode.removeChild(this.element);
            }
        }
        /**
         * Utils
         */
        // Applies css `properties` to an element.
        function applyProperties(target, properties) {
            for (var key in properties) {
                target.style[key] = properties[key];
            }
        }
        if (!('ontouchstart' in window || navigator.msMaxTouchPoints)) init();
    })();
    $(function(){
        $(window).scroll(function(){  //只要窗口滚动,就触发下面代码
            var scrollt = document.documentElement.scrollTop + document.body.scrollTop; //获取滚动后的高度
            if( scrollt >200 ){  //判断滚动后高度超过200px,就显示
                $("#back_top").fadeIn(400); //淡入
            }else{
                $("#back_top").stop().fadeOut(400); //如果返回或者没有超过,就淡出.必须加上stop()停止之前动画,否则会出现闪动
            }
        });
        $("#back_top").click(function(){ //当点击标签的时候,使用animate在200毫秒的时间内,滚到顶部
            $("html,body").animate({scrollTop:"0px"},200);
        });
    });
</script>
</body>
</html>
相关文章
|
前端开发 JavaScript
111.【金橘社区1.0】(二)
111.【金橘社区1.0】
53 0
|
前端开发
111.【金橘社区1.0】(五)
111.【金橘社区1.0】
75 0
|
前端开发
111.【金橘社区1.0】(六)
111.【金橘社区1.0】
59 0
|
5月前
|
Linux 开发者
Linux底层驱动社区饮水机系统详解
在Linux驱动开发中,入门时通常会关注驱动程序的三大核心步骤:入口函数、出口函数和声明许可证。这些步骤构成了驱动程序的基本结构,是驱动与内核交互的基础。下面是对这三个步骤的简要说明:
|
前端开发 JavaScript Java
111.【金橘社区1.0】(一)
111.【金橘社区1.0】
118 0
111.【金橘社区1.0】(一)
|
SQL JavaScript 前端开发
111.【金橘社区1.0】(四)
111.【金橘社区1.0】
51 0
|
开发者
我和社区的2022
简述我和社区一路走来的点点滴滴
我和社区的2022
|
数据安全/隐私保护 Docker 容器
JetLinks 社区版安装
JetLinks 社区版安装
562 0
|
Cloud Native 数据可视化 关系型数据库
训练营 | 如何成为一名开源社区贡献者?
「云原生应用插件扩展训练营」由阿里云云原生团队围绕 KubeVela、OpenYurt、Koordinator、OpenKruise、Fluid 等云原生开源项目打造,为了帮助更多开发者感受开源社区的魅力,了解如何更快地参与社区贡献。
训练营 | 如何成为一名开源社区贡献者?
|
云计算 开发者
阿里云社区
学习阿里云