zoukankan      html  css  js  c++  java
  • 新闻实时分析系统 大数据Web可视化分析系统开发

    1.基于业务需求的WEB系统设计

     

    2.下载Tomcat并创建Web工程并配置相关服务

    下载tomcat,解压并启动tomcat服务。

    1)新建web app项目

     

    创建好之后的效果

     

    2)对tomcat进行配置

     

     

    3.Web系统数据处理服务层开发

    WeblogService代码开发

    package com.spark.service;

     

    import java.sql.Connection;

    import java.sql.DriverManager;

    import java.sql.PreparedStatement;

    import java.sql.ResultSet;

    import java.util.HashMap;

    import java.util.Map;

     

    /**

     * Created by Administrator on 2017/10/17.

     */

    public class WeblogService {

        static String url ="jdbc:mysql://bigdata-pro01.kfk.com:3306/test";

        static String username="root";

        static String password="123456";

     

        public  Map queryWeblogs() {

            Connection conn = null;

            PreparedStatement pst = null;

            String[] titleNames = new String[20];

            String[] titleCounts = new String[20];

            Map retMap = new HashMap();

            try{

                Class.forName("com.mysql.jdbc.Driver");

                conn = DriverManager.getConnection(url,username,password);

                String query_sql = "select titleName,count from webCount where 1=1 order by count desc limit 20";

                pst = conn.prepareStatement(query_sql);

                ResultSet rs = pst.executeQuery();

                int i = 0;

                while (rs.next()){

                    String titleName = rs.getString("titleName");

                    String titleCount = rs.getString("count");

                    titleNames[i] = titleName;

                    titleCounts[i] = titleCount;

                    ++i;

                }

                retMap.put("titleName", titleNames);

                retMap.put("titleCount", titleCounts);

            }catch(Exception e){

                e.printStackTrace();

            }

                 return retMap;

        }

     

        public  String[] titleCount() {

            Connection conn = null;

            PreparedStatement pst = null;

            String[] titleSums = new String[1];

            try{

                Class.forName("com.mysql.jdbc.Driver");

                conn = DriverManager.getConnection(url,username,password);

                String query_sql = "select count(1) titleSum from webCount";

                pst = conn.prepareStatement(query_sql);

                ResultSet rs = pst.executeQuery();

                if(rs.next()){

                    String titleSum = rs.getString("titleSum");

                    titleSums[0] = titleSum;

                }

            }catch(Exception e){

                e.printStackTrace();

            }

            return titleSums;

        }

     

    }

    4.基于WebSocket协议的数据推送服务开发

    WeblogSocket代码开发

    package com.spark.service;

    import java.io.IOException;

    import java.util.HashMap;

    import java.util.Map;

     

    import com.alibaba.fastjson.JSON;

     

    import javax.websocket.OnClose;

    import javax.websocket.OnMessage;

    import javax.websocket.OnOpen;

    import javax.websocket.Session;

    import javax.websocket.server.ServerEndpoint;

    @ServerEndpoint("/websocket")

    public class WeblogSocket {

     

        WeblogService  weblogService = new WeblogService();

        @OnMessage

        public void onMessage(String message, Session session)

                throws IOException, InterruptedException {

            while(true){

                Map map = new HashMap();

                map.put("titleName", weblogService.queryWeblogs().get("titleName"));

                map.put("titleCount",weblogService.queryWeblogs().get("titleCount"));

                map.put("titleSum", weblogService.titleCount());

     

                session.getBasicRemote().

                        sendText(JSON.toJSONString(map));

                Thread.sleep(5000);

                map.clear();

            }

        }

        @OnOpen

        public void onOpen () {

            System.out.println("Client connected");

        }

        @OnClose

        public void onClose () {

            System.out.println("Connection closed");

        }

    }

    5.基于Echart框架的页面展示层开发

    1)echart、JQuery下载

    2)页面效果图选取及代码实现

     

     

    6.工程编译并打包发布

    参照之前将的idea打包方式,将spark web项目打包发布。

    7.启动各个服务并展示最终项目运行效果

     

  • 相关阅读:
    mybatis和spring整合
    Freemarker教程1(基本使用)
    mybatis教程6(逆向工程)
    mybatis教程4(动态SQL)
    mybatis教程5(延迟加载和缓存)
    mybatis教程2(配置文件)
    python作用域
    软件测试基础面试题
    http协议
    selenium自动化测试
  • 原文地址:https://www.cnblogs.com/misliu/p/11729308.html
Copyright © 2011-2022 走看看