Novel website | Online novel reading website based on Springboot+Vue

Author Home Page: Programming Compass

About the author: High-quality creator in the Java field, CSDN blog expert, CSDN content partner, Nuggets guest author, Alibaba Cloud blog expert, 51CTO guest author, years of experience in architect design, resident lecturer in Tencent Classroom

Main contents: Java projects, Python projects, front-end projects, artificial intelligence and big data, resume templates, study materials, interview question bank, technical mutual assistance

Collect, like and don’t get lost. It’s good to follow the author.

Get the source code at the end of the article 

Project number: BS-PT-116

1. Introduction to the environment

Locale: Java: jdk1.8

Database: Mysql: mysql5.7

Application server: Tomcat: tomcat8.5.31

Development tools: IDEA or eclipse

Development technology: Springboot+Vue

2. Project Introduction

This project develops and implements an online novel reading website platform based on Springboot+Vue. There are three main categories of system design users: readers, authors, and administrators. When users register, they enter the platform as a reader and can change their identity to be an author. Readers who log in to the system can view and read published novel chapters online, and comment, like and report online. They can also view novel news and platform announcement news published by the platform. . In addition to viewing novels, authors can log in to the platform to publish novels and content online and create online. All information is managed and operated by the platform administrator, including personnel management, novel management, chapter management, type management, report management, comment management, news management, system management (carousel management, hyperlink management), etc.

3. System display

System homepage

Novel list

Novel Reading-Like-Report

Information information view

Personal center

draft box

Personal comment management

Profile management

Administrator logs into the system

Author management

Novel classification management

Novel management

Comment-Report-Like Management

Platform news management and category management

System Management

4. Core code display

package com.spring.controller;

import com.spring.util.DESUtil;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 验证码控制器
 */
@Controller
public class CaptchaController extends BaseController {

    /**
     * 输出验证码图片,并记录session “random” 里等待登录时写入
     */
    @RequestMapping("/captcha")
    public String Index() {
        // 把验证码字符串写入session 中,保存待下次验证时使用
        String sRand = createRandomString(4);

        try {
            // 输出渲染好的内容到前端浏览器
            if (isAjax()) {
                String result = null;
                do {
                    try {
                        result = DESUtil.encrypt("CaptchControllerPassword", sRand);
                    } catch (Exception e) {
                        result = null;
                    }
                    if (result != null) {
                        if (!sRand.equals(DESUtil.decrypt("CaptchControllerPassword", result))) {
                            result = null; // 解不出来所以出错
                        }
                    }
                } while (result == null);

                assign("url", "/randtocaptch?captchToken=" + urlencode(result));
                assign("token", result);
                return json();
            } else {
                //byte[] img = xxx;
                response.setContentType("image/jpeg"); // 定义输出类型为 图片
                response.setHeader("Pragma", "No-cache"); // 设置为无缓存
                response.setHeader("Cache-Control", "no-cache"); // 设置为无缓存
                response.setDateHeader("Expires", 0); // 设置缓存时间为0秒后过期
                request.getSession().setAttribute("random", sRand);
                ServletOutputStream stream = response.getOutputStream();
                createCaptch(sRand, stream);
                stream.flush();
                stream.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "success";
    }

    /**
     * url 编码,中文要进行编码输出
     * @param str
     * @return
     */
    public static String urlencode(Object str) {
        try {
            return java.net.URLEncoder.encode(String.valueOf(str), "UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return str.toString();
    }

    /**
     * 使用上面的加密字符串生成验证码
     * @return
     */
    @RequestMapping("/randtocaptch")
    public String getCaptch() throws IOException {
        String captchToken = request.getParameter("captchToken");
        String sRand = DESUtil.decrypt("CaptchControllerPassword", captchToken);
        HttpSession session = request.getSession();
        {
            //byte[] img = xxx;
            response.setContentType("image/jpeg"); // 定义输出类型为 图片
            response.setHeader("Pragma", "No-cache"); // 设置为无缓存
            response.setHeader("Cache-Control", "no-cache"); // 设置为无缓存
            response.setDateHeader("Expires", 0); // 设置缓存时间为0秒后过期
            ServletOutputStream stream = response.getOutputStream();
            createCaptch(sRand, stream);
            stream.flush();
            stream.close();
        }
        return "success";
    }

    private String createRandomString(int len) {
        // 生成随机数类
        Random random = new Random();
        String result = "";
        for (int i = 0; i < len; i++) {
            String rand = String.valueOf(random.nextInt(10));
            result += rand;
        }
        return result;
    }

    private void createCaptch(String randomstr, OutputStream stream) {
        int width = 60, height = 20; // 定义图片宽为 60  高度为 20

        // 创建图片缓冲区
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

        // 获取渲染画板
        Graphics g = image.getGraphics();

        // 生成随机数类
        Random random = new Random();

        // 设置颜色
        g.setColor(getRandColor(200, 250));

        // 绘制矩形
        g.fillRect(0, 0, width, height);

        // 设置字体信息
        g.setFont(new Font("Times New Roman", Font.PLAIN, 18));

        // 设置颜色信息
        g.setColor(getRandColor(160, 200));

        // 写入干扰线
        for (int i = 0; i < 155; i++) {
            int x = random.nextInt(width);
            int y = random.nextInt(height);
            int xl = random.nextInt(12);
            int yl = random.nextInt(12);
            g.drawLine(x, y, x + xl, y + yl);
        }

        // 写入验证码字符串
        for (int i = 0; i < randomstr.length(); i++) {
            String rand = randomstr.substring(i, i + 1); //String.valueOf(random.nextInt(10));

            g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
            g.drawString(rand, 13 * i + 6, 16);
        }
        g.dispose(); // 释放画板

        try {
            // 输出渲染好的内容到前端浏览器

            ImageIO.write(image, "JPEG", stream);
            stream.flush();
            stream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取随机颜色
     * @param fc
     * @param bc
     * @return
     */
    protected Color getRandColor(int fc, int bc) {
        Random random = new Random();
        if (fc > 255) fc = 255;
        if (bc > 255) bc = 255;
        int r = fc + random.nextInt(bc - fc);
        int g = fc + random.nextInt(bc - fc);
        int b = fc + random.nextInt(bc - fc);
        return new Color(r, g, b);
    }
}
package com.spring.controller;

import com.jntoo.db.*;
import com.jntoo.db.utils.*;
import com.spring.dao.*;
import com.spring.entity.*;
import com.spring.service.*;
import com.spring.util.*;
import com.spring.util.Info;
import java.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import tk.mybatis.mapper.entity.Example;

/**
 * 点赞 */
@Controller
public class DianzanController extends BaseController {

    @Autowired
    private DianzanMapper dao;

    @Autowired
    private DianzanService service;

    @Autowired
    private PinglunService serviceRead;

    /**
     *  后台列表页
     *
     */
    @RequestMapping("/dianzan_list")
    public String list() {
        // 检测是否有登录,没登录则跳转到登录页面
        if (!checkLogin()) {
            return showError("尚未登录", "./login.do");
        }

        String order = Request.get("order", "id"); // 获取前台提交的URL参数 order  如果没有则设置为id
        String sort = Request.get("sort", "desc"); // 获取前台提交的URL参数 sort  如果没有则设置为desc
        int pagesize = Request.getInt("pagesize", 12); // 获取前台一页多少行数据
        Example example = new Example(Dianzan.class); //  创建一个扩展搜索类
        Example.Criteria criteria = example.createCriteria(); // 创建一个扩展搜索条件类
        String where = " 1=1 "; // 创建初始条件为:1=1
        where += getWhere(); // 从方法中获取url 上的参数,并写成 sql条件语句
        criteria.andCondition(where); // 将条件写进上面的扩展条件类中
        if (sort.equals("desc")) { // 判断前台提交的sort 参数是否等于  desc倒序  是则使用倒序,否则使用正序
            example.orderBy(order).desc(); // 把sql 语句设置成倒序
        } else {
            example.orderBy(order).asc(); // 把 sql 设置成正序
        }
        int page = request.getParameter("page") == null ? 1 : Integer.valueOf(request.getParameter("page")); // 获取前台提交的URL参数 page  如果没有则设置为1
        page = Math.max(1, page); // 取两个数的最大值,防止page 小于1
        List<Dianzan> list = service.selectPageExample(example, page, pagesize); // 获取当前页的行数

        // 将列表写给界面使用
        assign("totalCount", request.getAttribute("totalCount"));
        assign("list", list);
        assign("orderby", order); // 把当前排序结果写进前台
        assign("sort", sort); // 把当前排序结果写进前台
        return json(); // 将数据写给前端
    }

    public String getWhere() {
        _var = new LinkedHashMap(); // 重置数据
        String where = " ";
        // 判断URL 参数pinglunid是否大于0
        if (Request.getInt("pinglunid") > 0) {
            // 大于0 则写入条件
            where += " AND pinglunid='" + Request.getInt("pinglunid") + "' ";
        }
        // 以下也是一样的操作,判断是否符合条件,符合则写入sql 语句
        if (!Request.get("dianzanren").equals("")) {
            where += " AND dianzanren LIKE '%" + Request.get("dianzanren") + "%' ";
        }
        return where;
    }

    /**
     * 评论人列表
     */
    @RequestMapping("/dianzan_list_pinglunren")
    public String listpinglunren() {
        // 检测是否有登录,没登录则跳转到登录页面
        if (!checkLogin()) {
            return showError("尚未登录", "./login.do");
        }
        String order = Request.get("order", "id"); // 获取前台提交的URL参数 order  如果没有则设置为id
        String sort = Request.get("sort", "desc"); // 获取前台提交的URL参数 sort  如果没有则设置为desc
        int pagesize = Request.getInt("pagesize", 12); // 获取前台一页多少行数据

        Example example = new Example(Dianzan.class); //  创建一个扩展搜索类
        Example.Criteria criteria = example.createCriteria(); // 创建一个扩展搜索条件类
        // 初始化一个条件,条件为:评论人=当前登录用户
        String where = " pinglunren='" + request.getSession().getAttribute("username") + "' ";
        where += getWhere();

        criteria.andCondition(where); // 将条件写入
        if (sort.equals("desc")) { // 注释同list
            example.orderBy(order).desc(); // 注释同list
        } else {
            example.orderBy(order).asc(); // 注释同list
        }

        int page = request.getParameter("page") == null ? 1 : Integer.valueOf(request.getParameter("page")); // 注释同list
        page = Math.max(1, page); // 注释同list

        List<Dianzan> list = service.selectPageExample(example, page, pagesize);
        assign("totalCount", request.getAttribute("totalCount"));
        assign("list", list);
        assign("orderby", order);
        assign("sort", sort);
        return json(); // 将数据写给前端
    }

    /**
     * 点赞人列表
     */
    @RequestMapping("/dianzan_list_dianzanren")
    public String listdianzanren() {
        // 检测是否有登录,没登录则跳转到登录页面
        if (!checkLogin()) {
            return showError("尚未登录", "./login.do");
        }
        String order = Request.get("order", "id"); // 获取前台提交的URL参数 order  如果没有则设置为id
        String sort = Request.get("sort", "desc"); // 获取前台提交的URL参数 sort  如果没有则设置为desc
        int pagesize = Request.getInt("pagesize", 12); // 获取前台一页多少行数据

        Example example = new Example(Dianzan.class); //  创建一个扩展搜索类
        Example.Criteria criteria = example.createCriteria(); // 创建一个扩展搜索条件类
        // 初始化一个条件,条件为:点赞人=当前登录用户
        String where = " dianzanren='" + request.getSession().getAttribute("username") + "' ";
        where += getWhere();

        criteria.andCondition(where); // 将条件写入
        if (sort.equals("desc")) { // 注释同list
            example.orderBy(order).desc(); // 注释同list
        } else {
            example.orderBy(order).asc(); // 注释同list
        }

        int page = request.getParameter("page") == null ? 1 : Integer.valueOf(request.getParameter("page")); // 注释同list
        page = Math.max(1, page); // 注释同list

        List<Dianzan> list = service.selectPageExample(example, page, pagesize);
        assign("totalCount", request.getAttribute("totalCount"));
        assign("list", list);
        assign("orderby", order);
        assign("sort", sort);
        return json(); // 将数据写给前端
    }

    @RequestMapping("/dianzan_add")
    public String add() {
        _var = new LinkedHashMap(); // 重置数据
        int id = Request.getInt("id"); // 根据id 获取 评论模块中的数据
        Pinglun readMap = serviceRead.find(id);
        // 将数据行写入给前台jsp页面
        assign("readMap", readMap);

        return json(); // 将数据写给前端
    }

    @RequestMapping("/dianzan_updt")
    public String updt() {
        _var = new LinkedHashMap(); // 重置数据
        int id = Request.getInt("id");
        // 获取行数据,并赋值给前台jsp页面
        Dianzan mmm = service.find(id);
        assign("mmm", mmm);
        assign("updtself", 0);

        return json(); // 将数据写给前端
    }

    /**
     * 添加内容
     * @return
     */
    @RequestMapping("/dianzaninsert")
    public String insert() {
        _var = new LinkedHashMap(); // 重置数据
        String tmp = "";
        Dianzan post = new Dianzan(); // 创建实体类
        // 设置前台提交上来的数据到实体类中
        post.setPinglunid(Request.getInt("pinglunid"));

        post.setBiao(Request.get("biao"));

        post.setBiaoid(Request.getInt("biaoid"));

        post.setBiaoti(Request.get("biaoti"));

        post.setPingfen(Request.get("pingfen"));

        post.setPinglunneirong(Request.get("pinglunneirong"));

        post.setPinglunren(Request.get("pinglunren"));

        post.setDianzanren(Request.get("dianzanren"));

        post.setPinglunid(Request.getInt("pinglunid"));

        Dianzan dz = DB.name(Dianzan.class).where("pinglunid" , post.getPinglunid()).where("dianzanren" , post.getDianzanren()).find();

        if(dz!= null){
            DB.name(Dianzan.class).delete(dz.getId());
            return jsonResult(-1);
        }

        service.insert(post); // 插入数据
        int charuid = post.getId().intValue();
        Query.execute("update pinglun set dianzanshu=dianzanshu+1 where id='" + request.getParameter("pinglunid") + "'");

        if (isAjax()) {
            return jsonResult(post);
        }
        return showSuccess("保存成功", Request.get("referer").equals("") ? request.getHeader("referer") : Request.get("referer"));
    }

    /**
     * 更新内容
     * @return
     */
    @RequestMapping("/dianzanupdate")
    public String update() {
        _var = new LinkedHashMap(); // 重置数据
        // 创建实体类
        Dianzan post = new Dianzan();
        // 将前台表单数据填充到实体类
        if (!Request.get("pinglunid").equals("")) post.setPinglunid(Request.getInt("pinglunid"));
        if (!Request.get("biao").equals("")) post.setBiao(Request.get("biao"));
        if (!Request.get("biaoid").equals("")) post.setBiaoid(Request.getInt("biaoid"));
        if (!Request.get("biaoti").equals("")) post.setBiaoti(Request.get("biaoti"));
        if (!Request.get("pingfen").equals("")) post.setPingfen(Request.get("pingfen"));
        if (!Request.get("pinglunneirong").equals("")) post.setPinglunneirong(Request.get("pinglunneirong"));
        if (!Request.get("pinglunren").equals("")) post.setPinglunren(Request.get("pinglunren"));
        if (!Request.get("dianzanren").equals("")) post.setDianzanren(Request.get("dianzanren"));

        post.setId(Request.getInt("id"));
        service.update(post); // 更新数据
        int charuid = post.getId().intValue();

        if (isAjax()) {
            return jsonResult(post);
        }

        return showSuccess("保存成功", Request.get("referer")); // 弹出保存成功,并跳转到前台提交的 referer 页面
    }

    /**
     *  删除
     */
    @RequestMapping("/dianzan_delete")
    public String delete() {
        _var = new LinkedHashMap(); // 重置数据
        if (!checkLogin()) {
            return showError("尚未登录");
        }
        int id = Request.getInt("id"); // 根据id 删除某行数据
        Map map = Query.make("dianzan").find(id);

        service.delete(id); // 根据id 删除某行数据
        Query.execute("update pinglun set dianzanshu=dianzanshu-1 where id='" + map.get("pinglunid") + "'");

        return showSuccess("删除成功", request.getHeader("referer")); //弹出删除成功,并跳回上一页
    }
}

5. Display of related works

Practical projects based on Java development, Python development, PHP development, C# development and other related languages

Front-end practical projects developed based on Nodejs, Vue and other front-end technologies

Related works based on WeChat applet and Android APP application development

Development and application of embedded Internet of Things based on 51 microcontroller and other embedded devices

AI intelligent applications based on various algorithms

Various data management and recommendation systems based on big data

 

 

Guess you like

Origin blog.csdn.net/whirlwind526/article/details/132823616