基于SpringBoot和MySQL实现的在线小说平台

基于SpringBoot和MySQL实现的在线小说平台 1,项目简介 1,1 简介 制作小说阅读网可以给作者和读者提供一个相互交流的平台,作者将自己满 意的作品发布到这个平台让更多的人看到它们

本文包含相关资料包-----> 点击直达获取<-------

基于SpringBoot和MySQL实现的在线小说平台

1.项目简介

1.1 简介

制作小说阅读网可以给作者和读者提供一个相互交流的平台,作者将自己满 意的作品发布到这个平台让更多的人看到它们,而读者可以在这个平台寻找自己 感兴趣的作品并发布自己对作品的评论,作者能及时根据读者的评论来修改自己 的作品内容、调解创作思路。 这个平台的存在也可以减少买小说书的次数,节约 不少金钱。同时为了后期添加数据的便捷,本系统实现了爬虫网络小说平台上的数据,可快速插入数据。

1.2技术栈

  • Springboot

  • MybatisPlus

  • LayUI

  • Druid

  • Htmlunit

  • Mysql

2.数据库设计

2.1 表结构

chapter表

chapter_content表

collection表

fiction表

fiction_shelf表

user表

2.2 E-R图

3.项目实现

3.1 JsoupUitl工具类

```java / * Jsoup 工具类 */ public class JsoupUtil { private static final Logger log = LoggerFactory.getLogger(HttpAspect.class); / * @param content * @return 删除Html标签 / public static String delHTMLTag(String content) { content = content.replaceAll("\&[a-zA-Z]{1,10};", "").replaceAll("<[^>] >", "").replaceAll("[(/>)<]", ""); // 去除字符串中的空格 回车 换行符 制表符 等 content = content.replaceAll("\s*|\t|\r|\n", ""); // 去除空格 content = content.replaceAll(" ", ""); return content; }

/**
 * 字符串转化为UTF-8
 *
 * @param str
 * @return
 */
public static String toUTF8(String str) {
    String result = str;
    try {
        result = changeCharSet(str, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return result;
}

private static String changeCharSet(String str, String newCharset) throws UnsupportedEncodingException {
    if (str != null) {
        // 用默认字符编码解码字符串。
        byte[] bs = str.getBytes();
        // 用新的字符编码生成字符串
        return new String(bs, newCharset);
    }
    return str;
}

public static String sub(String str) {

    if (!str.isEmpty()) {
        return str.substring(str.indexOf(":") + 1);
    }
    return null;
}

public static String subContent(String str) {

    if (!str.isEmpty()) {
        return str.substring(0, str.indexOf("http"));
    }
    return null;
}

/**
 * 获取链接的document对象
 */
public static Document getDoc(String url) {
    Map<String, String> header = new HashMap<String, String>();
    header.put("Host", "http://info.bet007.com");
    header.put("User-Agent", "  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0");
    header.put("Accept", "  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    header.put("Accept-Language", "zh-cn,zh;q=0.5");
    header.put("Accept-Charset", "  GB2312,utf-8;q=0.7,*;q=0.7");
    header.put("Connection", "keep-alive");
    boolean flag = false;
    Document document = null;
    int i=0;
    do {
        try {
            document = Jsoup
                    .connect(url)
                    .header("Host","www.shuquge.com")
                    .header("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
                    .header("Accept-Encoding","gzip, deflate")
                    .header("Accept-Language","zh-CN,zh;q=0.9")
                    .header("Cache-Control","no-cache")
                    .header("Connection","keep-alive")
                    .header("Pragma","no-cache")
                    .header("Upgrade-Insecure-Requests","1")
                    .timeout(5000)
                    .userAgent("Mozilla")//模拟浏览器
                    .get();
            flag = false;
        } catch (IOException e) {
            i++;
            log.info("获取html失败了"+i+"次");
            flag = true;
        }
    } while (flag);
    return document;
}

public static void main(String[] args) {
    Document doc = getDoc("http://www.shuquge.com/txt/8659/33435905.html");
    System.out.println("doc = " + doc);
}

public static boolean isConnection(String url) {
    boolean flag = false;
    int counts = 0;
    if (null == url || url.length() <= 0) {
        return flag;
    }
    while (counts < 10) {
        try {
            HttpURLConnection connection = (HttpURLConnection) new URL(url)
                    .openConnection();
            int state = connection.getResponseCode();
            if (state == 200) {
                flag = true;
            }
            break;
        } catch (Exception e) {
            counts++;
            continue;
        }
    }
    return flag;
}

} ```

3.2 爬虫IP配置类

```java public class IpUtil { public static String getIpAddr(HttpServletRequest request) { String ipAddress = null; try { ipAddress = request.getHeader("x-forwarded-for"); if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { ipAddress = request.getHeader("Proxy-Client-IP"); } if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { ipAddress = request.getHeader("WL-Proxy-Client-IP"); } if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { ipAddress = request.getRemoteAddr(); if (ipAddress.equals("127.0.0.1")) { // 根据网卡取本机配置的IP InetAddress inet = null; try { inet = InetAddress.getLocalHost(); } catch (UnknownHostException e) { e.printStackTrace(); } ipAddress = inet.getHostAddress(); } } // 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割 if (ipAddress != null && ipAddress.length() > 15) { // " . . . ".length() // = 15 if (ipAddress.indexOf(",") > 0) { ipAddress = ipAddress.substring(0, ipAddress.indexOf(",")); } } } catch (Exception e) { ipAddress=""; } // ipAddress = this.getRequest().getRemoteAddr();

    return ipAddress;
}

} ```

3.3 主要代码

```java /* * 文章章节 控制器 / @Controller @RequestMapping("chapter") public class ChapterController { private final IChapterService iChapterService; private final IFictionService iFictionService; private final IChapterContentService iChapterContentService; private final IFictionShelfService iFictionShelfService;

public ChapterController(IChapterService iChapterService, IFictionService iFictionService, IChapterContentService iChapterContentService, IFictionShelfService iFictionShelfService) {
    this.iChapterService = iChapterService;
    this.iFictionService = iFictionService;
    this.iChapterContentService = iChapterContentService;
    this.iFictionShelfService = iFictionShelfService;
}

/**
 * 返回一本小说
 */
@RequestMapping(value = "info/{fiction_id}", method = RequestMethod.GET)
public String chapter(HttpServletRequest request, @PathVariable("fiction_id") int fiction_id, Model model) {
    Fiction fiction = iFictionService.getById(fiction_id);
    //添加点击量
    iFictionService.addView(fiction);
    //检查该本小说是否保存在书架
    int i = iFictionShelfService.isShelf(request, fiction_id);
    switch (i){
        case 0: model.addAttribute("presence",0);
        break;
        case 1: model.addAttribute("presence",1);
        break;
        default:
    }
    model.addAttribute("fiction",fiction);
    model.addAttribute("title",fiction.getFictionName());
    return "chapter/info";
}

/**
 * 返回一本小说所有章节
 */
@RequestMapping(value = "list/{fiction_id}", method = RequestMethod.GET)
public String chapterList(@PathVariable("fiction_id") int fiction_id, Model model) {
    Fiction fiction = iFictionService.getById(fiction_id);
    List<Chapter> chapterList = iChapterService.queryByFictionIdList(fiction_id);
    model.addAttribute("fiction",fiction);
    model.addAttribute("list",chapterList);
    model.addAttribute("size",chapterList.size());
    model.addAttribute("title",fiction.getFictionName());
    return "chapter/list";
}

/**
 * 当前小说页
 */
@RequestMapping(value = "read/{fiction_id}/{sort}", method = RequestMethod.GET)
public String chapterInfo(HttpServletRequest request,Model model, @PathVariable("fiction_id") int fiction_id,@PathVariable("sort") int sort) {
    //更新用户阅读章节
    HttpSession session = request.getSession();

    if (null!=session.getAttribute("id")){
        int id = iFictionShelfService.updateShelf(fiction_id, (Integer) session.getAttribute("id"), sort);
        if (id!=1){
            System.out.println("更新用户章节失败");
        }
    }
    Chapter chapter=iChapterService.netChapter(fiction_id,sort);
    if (null!=chapter){
        //获取小说内容
        ChapterContent chapterContent=iChapterContentService.getById(chapter.getContentId());
        model.addAttribute("chapter",chapter);
        model.addAttribute("content",chapterContent);
        model.addAttribute("title",chapter.getChapterTitle());
    }
    return "chapter/read";
}


/**
 * 上下页
 */
@RequestMapping(value = "netRead/{fiction_id}/{sort}/{status}",method = RequestMethod.GET)
public String netChapter(@PathVariable("fiction_id") int fiction_id,@PathVariable("sort") int sort,@PathVariable("status") int status,Model model) {
    if (status==1){
        if (sort!=1){
            sort=sort-1;
        }
    }else {
        sort=sort+1;
    }
    Chapter chapter = iChapterService.netChapter(fiction_id,sort);
    //获取小说内容
    ChapterContent chapterContent=iChapterContentService.getById(chapter.getContentId());
    model.addAttribute("chapter",chapter);
    model.addAttribute("content",chapterContent);
    model.addAttribute("title",chapter.getChapterTitle());
    return "chapter/read";
}

} ```

3.4 前端控制器

```java /* * 前端控制器 / @Controller public class FictionShelfController { private final IFictionShelfService iFictionShelfService; @Autowired public FictionShelfController(IFictionShelfService iFictionShelfService) { this.iFictionShelfService = iFictionShelfService; }

/**
 * 书架
 */
@RequestMapping(value = "shelf")
public String Shelf(HttpServletRequest request, Model model) {
    HttpSession session = request.getSession();
    try {
        List<ShelfVo> list = iFictionShelfService.queryByUserId((Integer) session.getAttribute("id"));
        model.addAttribute("list",list);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "shelf/shelf";
}

/**
 * 用户加入书架
 * @param Fiction_id 小说id
 * @return 成功或者失败
 */
@ResponseBody
@RequestMapping(value = "addShelf")
public Result AddShelf(HttpServletRequest request, @RequestParam("fiction_id") int Fiction_id) {

    return iFictionShelfService.addShelf(request, Fiction_id);
}

/**
 *  从书架删除小说
 */
@ResponseBody
@RequestMapping(value = "deleteShelf")
public Result deleteShelf(HttpServletRequest request, @RequestParam("id") int id){
    HttpSession session = request.getSession();
    int userId= (int) session.getAttribute("id");
    int i = iFictionShelfService.deleteShelf(id, userId);
    if (i==0){
        return new Result(-1,"移除书架失败");
    }
    return new Result(200,"移除书架成功");
}

} ```

4.项目展示

登录

注册

头部

中间

底部

书架

小说详情

章节列表

阅读

抓取小说页面

抓取地址

代码截图

参考文献

  • 基于Web系统的计算机编程语言书籍交流系统设计与开发(吉林大学·刘峰兵)
  • 云南瑞升烟草技术集团有限公司网上阅读系统的设计与实现(电子科技大学·杨舒然)
  • 基于SSH框架的博客用户分享平台的设计与实现(河北工业大学·刘磊)
  • 基于SSH框架的博客用户分享平台的设计与实现(河北工业大学·刘磊)
  • 基于SSH框架的博客用户分享平台的设计与实现(河北工业大学·刘磊)
  • 基于OAuth2.0协议的企业分布式授权系统设计与实现(华中科技大学·支猛)
  • 基于jsp技术网上书店系统的设计与实现(电子科技大学·胡朝斌)
  • 基于JAVA WEB的虚拟数字图书电子商务平台设计与实现(吉林大学·霍剑峰)
  • 网上购书电子商务系统(吉林大学·谷丰)
  • 基于SSH框架的博客用户分享平台的设计与实现(河北工业大学·刘磊)
  • 基于Spring Boot的校园轻博客系统的设计与实现(华中科技大学·邓笑)
  • 业务逻辑层模型的研究和应用(大连海事大学·王家顺)
  • 基于Spring Boot的校园轻博客系统的设计与实现(华中科技大学·邓笑)
  • 云南瑞升烟草技术集团有限公司网上阅读系统的设计与实现(电子科技大学·杨舒然)
  • 网上购书电子商务系统(吉林大学·谷丰)

本文内容包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主题。发布者:源码导航 ,原文地址:https://m.bishedaima.com/yuanma/35466.html

相关推荐

发表回复

登录后才能评论