基于Springboot的在线网络小说阅读网站的设计与实现

摘  要

现在是互联网快速发展的时代,网络是一种新媒体的类型,被称为“第四媒体”,随着越来越多的人进入互联网时代,网络阅读一种由文本的变化所带来的新的阅读方式,借助计算机、网络技术来获取多媒体合成信息和知识的阅读行为,对人们来说是一个新的阅读体验,改变了阅读的媒介(以前是纸质的),是时代的进步。

基于Springboot的在线网络小说阅读网站主要实现了在线写作、在线阅读、评价小说、更新章节、查询小说、将小说加入书架、阅读记录、购买平台VIP来阅读收费小说等功能。在本网站中一个人可以创作多本小说、用户作为其他人的读者也作为自己作品作者,可以通过查询功能根据小说名与作者名来查询自己想要观看的小说,在购买一个月、三个月等不同月份的平台VIP后可以看其他作者写的收费小说,在支付成功后会显示截至到期的期限。

本系统使用纯面向对象的Java语言,Springboot作为后端框架,MySQL数据库等技术进行开发,使用JSP+CSS+JS对网站前端界面进行设计,更采用了JQuery这款轻量级的JS框架。用Navicat for MySQL管理MySQL数据库。

关键词 Springboot;阅读;Java语言;MySQL数据库

演示视频(去blibli观看):

springboot mybatis在线小说网站java小说网站毕业设计

 YML配置:

server:
  port: 8080
  servlet:
    context-path: /novel
    multipart:
      max-file-size: 10MB  #单个文件
      max-request-size: 100MB #总文件大小

spring:
     datasource:
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://localhost:3306/db_novel?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8
        username: root
        password: root
     jpa:
       show-sql: true
     mvc:
       view:
         prefix: /WEB-INF/views/
         suffix: .jsp


mybatis:
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.novel.entity
   #devtools插件
devtools:
    restart:
      enabled: true #是否支持热部署
#mybaatis分页插件pagehelper设置
pagehelper:
  pagehelperDialect: mysql
  reasonable: true
  support-methods-arguments: true

  # 打印sql
logging:
    level:
       com.novel.dao: DEBUG

支付宝沙箱支付:


    /**
     * 用户充值支付
     */
    @RequestMapping("userPay")
    public void pay(Integer month,HttpServletResponse rep, Model model,HttpSession session){
        User user = (User) session.getAttribute("user");
        session.setAttribute("month",month);
        //接入支付宝沙箱支付
//获得初始化的AlipayClient
        AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
        //设置请求参数
        AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
        alipayRequest.setReturnUrl(AlipayConfig.return_url);
        //alipayRequest.setNotifyUrl(AlipayConfig.notify_url);
        try{
        //商户订单号,商户网站订单系统中唯一订单号,必填
        String out_trade_no = UUID.randomUUID().toString();
        //付款金额,必填
        int total = month*10;
        String total_amount =String.valueOf(total);
        //订单名称,必填
        String subject   ="用户"+user.getUsername()+"订单";
        //商品描述,可空
        String body = "";

        alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","
                + "\"total_amount\":\""+ total_amount +"\","
                + "\"subject\":\""+ subject +"\","
                + "\"body\":\""+ body +"\","
                + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");

        //请求
        String result = alipayClient.pageExecute(alipayRequest).getBody();

        rep.setContentType("text/html;charset=" + AlipayConfig.charset);
        //直接将完整的表单html输出到页面
        rep.getWriter().write(result);
        rep.getWriter().flush();
        rep.getWriter().close();
        }catch (Exception e){
           e.printStackTrace();
        }
     }

    /**
     * 支付成功以后回调
     * @return
     */
    @RequestMapping("payreturn")
     public String payreturn(HttpSession session,Model model){
        User user = (User) session.getAttribute("user");
        int month = (int) session.getAttribute("month");
        Order order = orderService.selectOneOrder(user.getUserid());
        int num=0;
        if(order!=null){
            int i = new Date().compareTo(order.getEndtime());
            if(i<0 || DateUtil.getStringDate(new Date()).equals(DateUtil.getStringDate(order.getEndtime()))){
                //更新
                order.setEndtime(DateUtil.subMonth(order.getEndtime(),month));
                order.setMonth(order.getMonth()+month);
                order.setTotalmoney(order.getTotalmoney()+(month*10));
                orderService.updateByPrimaryKey(order);
            }else{
                num++;
            }
        }else{
            num++;
        }

        if(num>0){
            order = new Order();
            order.setUserid(user.getUserid());
            order.setUsername(user.getUsername());
            order.setCreatetime(new Date());
            order.setStarttime(new Date());
            order.setEndtime(DateUtil.subMonth(new Date(),month));
            order.setMonth(month);
            order.setTotalmoney(month*10);
            orderService.insert(order);
        }
        session.setAttribute("uservip",1);
        return "redirect:/order/toPayPage";
     }

}