目 录
1 项目目的与意义
1.1项目背景说明
1.2项目目的与意义
2 软件开发环境与技术说明
2.1软件开发环境
2.2软件开发技术描述
3 系统分析与设计
3.1项目需求分析说明
3.2系统设计方案
4 系统源代码
4.1系统源代码文件说明
4.2源代码
5 系统使用说明书
6 参考资料
7 附件说明
1 项目目的与意义
1.1项目背景说明
“武汉街道空无一人,但是每个窗户后面都有配合应对疫情的市民。中国展现了惊人的集体行动力与合作精神。”这是世界卫生组织总干事高级顾问布鲁斯·艾尔沃德2月下旬在结束对中国的实地考察后发出的感慨。
放眼全中国,怀有浓厚家国情怀的中国人不计其数。来自中国各地的4.2万余名医护人员快速驰援湖北与武汉,义无反顾地成为“最美逆行者”,有人甚至为此献出了生命。正是抱定共克时艰的意志,14亿中国人齐心响应国家号召,自觉居家隔离,为疫情防控尽自己的一份力。艾尔沃德在考察中国防疫工作后曾动情地说,“中国人民的坚韧和奉献,极大延缓了新冠肺炎疫情传播。”联合国秘书长古特雷斯认为,“中国人民为防控疫情作出的牺牲,是对人类极大的贡献。”
美国破百万、全球大流行, 可以确定地说,目前我们正在经历本世纪以来最严重的灾难,其波及范围,人员伤亡,后续影响及对全球经济形势的损害都将是自二战以来最惨烈的。
目前疫情正在全球肆虐,已波及209个国家,地球上己几无一片净土。截止4月11日,全球确诊人数已近两百万,死亡人数达十余万,而且还在以每天数万确诊,上千死亡的速度飞速增长。目前除中国疫情基本受控之外,欧美各国疫情均在发酵中,拐点还远远没有到来。以现在疫情最严重的美国为例,预计拐点最快也要到月底,以目前的发展速度,达到百万级别确诊和十万级别死亡将是大概率事件。
新冠肺炎疫情对全球经济影响巨大,据最新数据预测,2020年全球经济将萎缩3.0%,为1930年以来遭遇的最大经济危机。不容乐观的是,面对多国放松封锁措施,世界卫生组织警告,疫情尚未到峰值。
1.2项目目的与意义
该项目的研究可以让人们每日清晰地看到世界的疫情数据,时刻关注世界疫情状况在当下也具有重要意义。
据全球疫情实时监控网站统计,每天都有十几亿的访问量,这也看到了大家对于实时的数据重视
2 软件开发环境与技术说明
2.1 软件开发环境
该系统应用eclipse使用JavaScript语言建立可视化界面
Python软件进行数据的爬取
Python标准库和扩展库:pymysql、 requests、bs4
数据库环境:MySQL
2.2软件开发技术描述
界面设计:应用JavaScript对界面进行包装
Python爬取数据连接:
url= https://ncov.dxy.cn/ncovh5/view/pneumonia?from=timeline&isappinstalled=0' # 请求地址 headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36'} # 创建头部信息 response = requests.get(url, headers=headers) # 发送网络请求 content = response.content.decode('utf-8') soup = BeautifulSoup(content, 'html.parser')
数据库连接:
Python连接MySQL数据库
db = pymysql.connect("localhost", "root", "0000", "yiqing", charset='utf8') cursor = db.cursor()
JavaScript连接MySQL数据库
conn=DriverManager.getConnection("jdbc:mysql://localhost:8080/疫情统计图/world?useUnicode=true&characterEncoding=utf-8","root","");
数据连接:
String sql="select * from world_map where now_time like '"+time+"%' "; String sql="select * from world_map where now_time like '"+time+"%' ORDER BY deadCount desc "; String sql="select * from world_map where now_time like '"+time+"%' order by curedCount desc "; //等等,此处不过多列举
网络连接:
Web:
疫情统计图 index.html index.htm index.jsp default.html default.htm default.jsp
Python连接JavaScript:
sql_world = "INSERT INTO world_map values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
正则字符串处理:
(.+?) (.*)
等等
3系统分析与设计
3.1项目需求分析说明
仿照约翰·霍普金斯大学制作全球疫情发布图(WEB版),可以实时访问。用例图如下:
3.2系统设计方案
数据库表:
Python爬取数据到数据库
框架设计图如下:
4 系统源代码
4.1系统源代码文件说明
文件 |
作用 |
Python文件 |
爬取世界疫情信息到Mysql |
dao包 |
对数据库进行操作 |
servlet包 |
函数代码 |
util包 |
连接数据库 |
entity包 |
定义类对象的set get方法和构造函数 |
src目录下所有文件 |
后台的java代码,支持界面所有操作 |
world.jsp |
实现界面 |
js和layui文件夹 |
调样式 |
css 和layui文件夹 |
美化界面 |
lib下所有文件 |
连接数据库操作需要引用的jar包 |
Xml文件 |
配置文件 |
chart下所有文件 |
用echart图表用来实现地图 |
|
|
4.2源代码
登录界面
![](http://img.e-com-net.com/image/info8/2b246dbcfe82488397e9aa432bbc4e31.gif)
1 package First; 2 3 4 import java.awt.*;//导入awt包 5 import javax.swing.*;//导入swing包 6 import java.awt.event.ActionListener;//导入awt包中的监听器事件包 7 import java.awt.event.ActionEvent;//导入awt包中的ActionEvent事件包 8 9 10 11 public class login extends JFrame { 12 13 14 public login() { 15 setSize(300,290);//设计窗体的大小 16 JLabel a=new JLabel("用户名"); //实例化JLabel对象 17 JLabel b=new JLabel("密 码"); 18 JTextField c=new JTextField(15);//实例化用户名文本框 19 JPasswordField d=new JPasswordField(15);//实例化密码框 20 d.setEchoChar('*');//将输入密码框中的密码以*显示出来 21 JButton e=new JButton("确定"); 22 JButton f=new JButton("重置"); 23 JButton g=new JButton("注册"); 24 setVisible(true);//使窗体可视化 25 Container mk=getContentPane();//获取一个容器 26 // 将用户名、密码的Jlabel和用户名JTextField文本框、密码JPasswordField密码框以及确定JButton、重置JButton、注册JButton添加到container容器里面 // 27 mk.add(a); 28 mk.add(b); 29 mk.add(c); 30 mk.add(d); 31 mk.add(e); 32 mk.add(f); 33 mk.add(g); 34 setBounds(300,300,300,290);//设置窗体的长宽各为300、300 让其显示在左上方的300、300处 35 mk.setLayout(null); 36 // a、b、c、d、e、f、g显示在container容器中的位置坐标 37 a.setBounds(10,40,50,18); 38 b.setBounds(10,80,50,18); 39 c.setBounds(60,40,200,18); 40 d.setBounds(60,80,200,18); 41 e.setBounds(110,180,60,30); 42 f.setBounds(30,180,60,30); 43 g.setBounds(190,180,60,30); 44 45 f.addActionListener(new ActionListener() {//对重置按钮添加监听事件 46 47 @Override 48 public void actionPerformed(ActionEvent arg0) { 49 // TODO Auto-generated method stub 50 c.setText("");//对用户名文本框进行重置 51 d.setText("");//对密码文本框进行重置 52 } 53 54 }); 55 e.addActionListener(new ActionListener() {//对确定按钮添加监听事件 56 57 @SuppressWarnings("deprecation") 58 @Override 59 public void actionPerformed(ActionEvent arg0) { 60 // TODO Auto-generated method stub 61 62 if(c.getText().trim().equals("py")&&new String(d.getPassword()).equals("123456")) {//equals函数进行用户名和密码的匹配 63 JOptionPane.showMessageDialog(null,"登录成功"); 64 65 new world();//进入到world这个窗体中 66 } 67 else if(c.getText().trim().equals("zs")&&new String(d.getPassword()).equals("123")) {//equals函数进行用户名和密码的匹配 68 JOptionPane.showMessageDialog(null,"登录成功"); 69 70 new Add();//进入到world这个窗体中 71 } 72 else { 73 JOptionPane.showMessageDialog(null, "登录失败"); 74 } 75 } 76 77 }); 78 g.addActionListener(new ActionListener(){//对注册按钮添加监听事件 79 @SuppressWarnings("deprecation") 80 @Override 81 public void actionPerformed(ActionEvent arg0) { 82 // TODO Auto-generated method stub 83 new zhuce();//进入都到zhuce窗体中 84 } 85 86 }); 87 88 } 89 public static void main(String[] args) { 90 new main(); 91 92 93 } 94 95 96 }
注册界面
![](http://img.e-com-net.com/image/info8/2b246dbcfe82488397e9aa432bbc4e31.gif)
package First; import java.sql.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import com.mysql.jdbc.Driver; import First.login; public class zhuce extends login { private static final long serialVersionUID = -1928970409928880648L; JLabel jlnumber = new JLabel("用户名:"); JLabel jpassword = new JLabel("密码:"); JTextField jtnumber = new JTextField("",20); JTextField jtpassword = new JTextField("",20); JButton buttonadd = new JButton("注册"); JButton buttonreturn = new JButton("取消"); public zhuce() { JPanel jpnumber = new JPanel(); JPanel jtpassword = new JPanel(); JPanel jpforbutton = new JPanel(new GridLayout(1,1)); jpnumber.add(jlnumber); jpnumber.add(jtnumber); jtpassword.add(jtpassword); jtpassword.add(jtpassword); jpforbutton.add(buttonadd); jpforbutton.add(buttonreturn); buttonadd.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ //Add Connection conn = null; Statement stat = null; PreparedStatement ps=null; String a1=jtnumber.getText(); String e2=jpassword.getText(); String sql = "INSERT INTO student(number,password) values('"+a1+"','"+e2+"')"; try{ Class.forName("com.mysql.jdbc.Driver"); System.out.println("JBDC 连接成功!"); }catch(Exception a){ System.out.println("JBDC 连接失败!"); a.printStackTrace(); } try{ conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/STU?useUnicode=true&characterEncoding=utf-8","root",""); //ps=conn.prepareStatement(sql); //ps.setString(1,jtnumber.getText()); //ps.setString(2,jtname.getText()); //ps.setString(3,jtsex.getText()); //ps.setString(4,jtbirthday.getText()); //ps.setString(5,jtdepartment.getText()); //ps.executeUpdate(); System.out.println("MySQL 连接成功!"); stat = conn.createStatement(); stat.executeUpdate(sql); System.out.println("插入数据成功!"); }catch (SQLException b){ b.printStackTrace(); }finally{ try{ conn.close(); System.out.println("MySQL 关闭成功"); }catch (SQLException c){ System.out.println("MySQL 关闭失败 "); c.printStackTrace(); } } }} ); buttonreturn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ login(); } }); this.setTitle("注册信息"); this.setLayout(new GridLayout(9,1)); this.add(jpnumber); this.add(jpassword); this.add(jpforbutton); this.setLocation(400,300); this.setSize(350,300); this.setVisible(true); } }
界面实现
jsp代码部分
![](http://img.e-com-net.com/image/info8/2b246dbcfe82488397e9aa432bbc4e31.gif)
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@page import="java.util.Date"%> 4 <%@page import="java.text.SimpleDateFormat"%> 5 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 6 7 8 9 10Insert title here 11 12 13 15 16 108 109 <% 110 111 %> 112 113114116全球疫情可视化展示
115117119 120 121time
118122125死亡人数123治愈人数124柱状图126 557 558
dao层
![](http://img.e-com-net.com/image/info8/2b246dbcfe82488397e9aa432bbc4e31.gif)
1 package dao; 2 3 import java.sql.Connection; 4 import java.sql.ResultSet; 5 import java.sql.SQLException; 6 import java.sql.Statement; 7 import java.util.ArrayList; 8 9 import entity.World; 10 import util.DBUtil; 11 12 public class Dao { 13 14 public ArrayListgetconfirmed(String time) { 15 String sql="select * from world_map where now_time like '"+time+"%' "; 16 System.out.println(time); 17 Connection con=null; 18 Statement state=null; 19 ResultSet rs=null; 20 boolean flag=false; 21 con=DBUtil.getConn(); 22 World bean=null; 23 ArrayList list=new ArrayList (); 24 try { 25 state=con.createStatement(); 26 rs=state.executeQuery(sql); 27 while(rs.next()) 28 { 29 bean=new World(); 30 bean.setProvinceName(rs.getString("provinceName")); 31 bean.setConfirmedCount(rs.getString("confirmedCount")); 32 bean.setSuspectedCount(rs.getString("suspectedCount")); 33 bean.setCuredCount(rs.getString("curedCount")); 34 bean.setDeadCount(rs.getString("deadCount")); 35 //System.out.println(bean.getName()+" "+bean.getConfirmed()); 36 list.add(bean); 37 } 38 } catch (SQLException e) { 39 // TODO 自动生成的 catch 块 40 e.printStackTrace(); 41 } 42 DBUtil.close(rs, state, con); 43 return list; 44 } 45 46 public ArrayList getdead(String time) { 47 String sql="select * from world_map where now_time like '"+time+"%' ORDER BY deadCount desc "; 48 System.out.println(time); 49 Connection con=null; 50 Statement state=null; 51 ResultSet rs=null; 52 boolean flag=false; 53 con=DBUtil.getConn(); 54 World bean=null; 55 ArrayList list=new ArrayList (); 56 try { 57 state=con.createStatement(); 58 rs=state.executeQuery(sql); 59 while(rs.next()) 60 { 61 bean=new World(); 62 bean.setProvinceName(rs.getString("provinceName")); 63 bean.setConfirmedCount(rs.getString("confirmedCount")); 64 bean.setSuspectedCount(rs.getString("suspectedCount")); 65 bean.setCuredCount(rs.getString("curedCount")); 66 bean.setDeadCount(rs.getString("deadCount")); 67 //System.out.println(bean.getName()+" "+bean.getConfirmed()); 68 list.add(bean); 69 } 70 } catch (SQLException e) { 71 // TODO 自动生成的 catch 块 72 e.printStackTrace(); 73 } 74 DBUtil.close(rs, state, con); 75 return list; 76 } 77 78 public ArrayList getcured(String time) { 79 String sql="select * from world_map where now_time like '"+time+"%' order by curedCount desc "; 80 System.out.println(time); 81 Connection con=null; 82 Statement state=null; 83 ResultSet rs=null; 84 boolean flag=false; 85 con=DBUtil.getConn(); 86 World bean=null; 87 ArrayList list=new ArrayList (); 88 try { 89 state=con.createStatement(); 90 rs=state.executeQuery(sql); 91 while(rs.next()) 92 { 93 bean=new World(); 94 bean.setProvinceName(rs.getString("provinceName")); 95 bean.setConfirmedCount(rs.getString("confirmedCount")); 96 bean.setSuspectedCount(rs.getString("suspectedCount")); 97 bean.setCuredCount(rs.getString("curedCount")); 98 bean.setDeadCount(rs.getString("deadCount")); 99 //System.out.println(bean.getCuredCount()); 100 list.add(bean); 101 } 102 } catch (SQLException e) { 103 // TODO 自动生成的 catch 块 104 e.printStackTrace(); 105 } 106 DBUtil.close(rs, state, con); 107 return list; 108 } 109 110 public ArrayList dataconfirmed() { 111 String sql="select * from world_map "; 112 Connection con=null; 113 Statement state=null; 114 ResultSet rs=null; 115 boolean flag=false; 116 con=DBUtil.getConn(); 117 World bean=null; 118 int sum=0; 119 int ans=0; 120 String data=null; 121 ArrayList list=new ArrayList (); 122 try { 123 state=con.createStatement(); 124 rs=state.executeQuery(sql); 125 while(rs.next()) 126 { 127 sum++; 128 bean=new World(); 129 bean.setProvinceName(rs.getString("now_time")); 130 if(sum==1) 131 data=bean.getProvinceName(); 132 bean.setConfirmedCount(rs.getString("confirmedCount")); 133 if(data.equals(bean.getProvinceName())) 134 ans+=Integer.parseInt(bean.getConfirmedCount()); 135 else 136 { 137 String timeString=data.substring(0,10); 138 World bean2=new World(); 139 bean2.setProvinceName(timeString); 140 bean2.setConfirmedCount(String.valueOf(ans)); 141 sum=1; 142 ans=0; 143 ans+=Integer.parseInt(bean.getConfirmedCount()); 144 data=bean.getProvinceName(); 145 list.add(bean2); 146 } 147 } 148 bean.setProvinceName(data.substring(0,10)); 149 bean.setConfirmedCount(String.valueOf(ans)); 150 list.add(bean); 151 } catch (SQLException e) { 152 // TODO 自动生成的 catch 块 153 e.printStackTrace(); 154 } 155 DBUtil.close(rs, state, con); 156 return list; 157 } 158 public ArrayList allworld(String time) { 159 String sql="select * from world_map where now_time like '"+time+"%' "; 160 System.out.println(time); 161 Connection con=null; 162 Statement state=null; 163 ResultSet rs=null; 164 boolean flag=false; 165 con=DBUtil.getConn(); 166 World bean=null; 167 ArrayList list=new ArrayList (); 168 try { 169 state=con.createStatement(); 170 rs=state.executeQuery(sql); 171 while(rs.next()) 172 { 173 bean=new World(); 174 bean.setProvinceName(rs.getString("provinceName")); 175 bean.setConfirmedCount(rs.getString("confirmedCount")); 176 bean.setSuspectedCount(rs.getString("suspectedCount")); 177 bean.setCuredCount(rs.getString("curedCount")); 178 bean.setDeadCount(rs.getString("deadCount")); 179 //System.out.println(bean.getName()+" "+bean.getConfirmed()); 180 list.add(bean); 181 } 182 } catch (SQLException e) { 183 // TODO 自动生成的 catch 块 184 e.printStackTrace(); 185 } 186 DBUtil.close(rs, state, con); 187 return list; 188 } 189 } 190 Dao.java 191
显示治愈人数、死亡人数、确诊人数功能
![](http://img.e-com-net.com/image/info8/2b246dbcfe82488397e9aa432bbc4e31.gif)
1 package servlet; 2 3 import java.io.IOException; 4 import java.util.Date; 5 import java.text.SimpleDateFormat; 6 import java.util.ArrayList; 7 8 import javax.servlet.ServletException; 9 import javax.servlet.annotation.WebServlet; 10 import javax.servlet.http.HttpServlet; 11 import javax.servlet.http.HttpServletRequest; 12 import javax.servlet.http.HttpServletResponse; 13 14 import com.google.gson.Gson; 15 16 import dao.Dao; 17 import entity.World; 18 19 /** 20 * Servlet implementation class Getconfirmed 21 */ 22 @WebServlet("/Getconfirmed") 23 public class Getconfirmed extends HttpServlet { 24 private static final long serialVersionUID = 1L; 25 26 /** 27 * @see HttpServlet#HttpServlet() 28 */ 29 public Getconfirmed() { 30 super(); 31 // TODO Auto-generated constructor stub 32 } 33 34 /** 35 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 36 */ 37 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 38 // TODO Auto-generated method stub 39 Dao dao=new Dao(); 40 request.setCharacterEncoding("utf-8"); 41 Date now = new Date(); 42 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 43 String Time = dateFormat.format(now);//格式化然后放入字符串中 44 String data=Time.substring(0,10); 45 ArrayListlist=dao.getconfirmed(data); 46 Gson gson = new Gson(); 47 response.setContentType("text/html;charset=utf-8"); 48 String json = gson.toJson(list); 49 response.getWriter().write(json); 50 System.out.println(json); 51 } 52 53 /** 54 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 55 */ 56 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 57 // TODO Auto-generated method stub 58 doGet(request, response); 59 } 60 61 } 62 Getconfirmed.java 63 64 package servlet; 65 66 import java.io.IOException; 67 import java.text.SimpleDateFormat; 68 import java.util.ArrayList; 69 import java.util.Date; 70 71 import javax.servlet.ServletException; 72 import javax.servlet.annotation.WebServlet; 73 import javax.servlet.http.HttpServlet; 74 import javax.servlet.http.HttpServletRequest; 75 import javax.servlet.http.HttpServletResponse; 76 77 import com.google.gson.Gson; 78 79 import dao.Dao; 80 import entity.World; 81 82 /** 83 * Servlet implementation class Getcured 84 */ 85 @WebServlet("/Getcured") 86 public class Getcured extends HttpServlet { 87 private static final long serialVersionUID = 1L; 88 89 /** 90 * @see HttpServlet#HttpServlet() 91 */ 92 public Getcured() { 93 super(); 94 // TODO Auto-generated constructor stub 95 } 96 97 /** 98 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 99 */ 100 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 101 Dao dao =new Dao(); 102 request.setCharacterEncoding("utf-8"); 103 Date now = new Date(); 104 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 105 String Time = dateFormat.format(now);//格式化然后放入字符串中 106 String data=Time.substring(0,10); 107 ArrayList list=dao.getcured(data); 108 Gson gson = new Gson(); 109 response.setContentType("text/html;charset=utf-8"); 110 String json = gson.toJson(list); 111 response.getWriter().write(json); 112 System.out.println(json); 113 } 114 115 /** 116 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 117 */ 118 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 119 // TODO Auto-generated method stub 120 doGet(request, response); 121 } 122 123 } 124 Getcured.java 125 126 package servlet; 127 128 import java.io.IOException; 129 import java.text.SimpleDateFormat; 130 import java.util.ArrayList; 131 import java.util.Date; 132 133 import javax.servlet.ServletException; 134 import javax.servlet.annotation.WebServlet; 135 import javax.servlet.http.HttpServlet; 136 import javax.servlet.http.HttpServletRequest; 137 import javax.servlet.http.HttpServletResponse; 138 139 import com.google.gson.Gson; 140 141 import dao.Dao; 142 import entity.World; 143 144 /** 145 * Servlet implementation class GetDead 146 */ 147 @WebServlet("/GetDead") 148 public class GetDead extends HttpServlet { 149 private static final long serialVersionUID = 1L; 150 151 /** 152 * @see HttpServlet#HttpServlet() 153 */ 154 public GetDead() { 155 super(); 156 // TODO Auto-generated constructor stub 157 } 158 159 /** 160 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 161 */ 162 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 163 Dao dao=new Dao(); 164 request.setCharacterEncoding("utf-8"); 165 Date now = new Date(); 166 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 167 String Time = dateFormat.format(now);//格式化然后放入字符串中 168 String data=Time.substring(0,10); 169 ArrayList list=dao.getdead(data); 170 Gson gson = new Gson(); 171 response.setContentType("text/html;charset=utf-8"); 172 String json = gson.toJson(list); 173 response.getWriter().write(json); 174 System.out.println(json); 175 } 176 177 /** 178 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 179 */ 180 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 181 // TODO Auto-generated method stub 182 doGet(request, response); 183 } 184 185 } 186 GetDead.java
实现日期控制
![](http://img.e-com-net.com/image/info8/2b246dbcfe82488397e9aa432bbc4e31.gif)
1 package servlet; 2 3 import java.io.IOException; 4 import java.util.ArrayList; 5 6 import javax.servlet.ServletException; 7 import javax.servlet.annotation.WebServlet; 8 import javax.servlet.http.HttpServlet; 9 import javax.servlet.http.HttpServletRequest; 10 import javax.servlet.http.HttpServletResponse; 11 12 import com.google.gson.Gson; 13 14 import dao.Dao; 15 import entity.World; 16 17 /** 18 * Servlet implementation class Dataconfirmed 19 */ 20 @WebServlet("/Dataconfirmed") 21 public class Dataconfirmed extends HttpServlet { 22 private static final long serialVersionUID = 1L; 23 24 /** 25 * @see HttpServlet#HttpServlet() 26 */ 27 public Dataconfirmed() { 28 super(); 29 // TODO Auto-generated constructor stub 30 } 31 32 /** 33 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 34 */ 35 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 36 Dao dao =new Dao(); 37 request.setCharacterEncoding("utf-8"); 38 ArrayListlist=dao.dataconfirmed(); 39 Gson gson = new Gson(); 40 response.setContentType("text/html;charset=utf-8"); 41 String json = gson.toJson(list); 42 response.getWriter().write(json); 43 System.out.println("日期变化曲线!"); 44 System.out.println(json); 45 } 46 47 /** 48 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 49 */ 50 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 51 // TODO Auto-generated method stub 52 doGet(request, response); 53 } 54 55 } 56 Dataconfirmed.java
具体实现
![](http://img.e-com-net.com/image/info8/2b246dbcfe82488397e9aa432bbc4e31.gif)
1 import json 2 3 import pymysql 4 import requests 5 from bs4 import BeautifulSoup 6 import datetime 7 8 url = 'https://ncov.dxy.cn/ncovh5/view/pneumonia?from=timeline&isappinstalled=0' # 请求地址 9 headers = { 10 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36'} # 创建头部信息 11 response = requests.get(url, headers=headers) # 发送网络请求 12 content = response.content.decode('utf-8') 13 soup = BeautifulSoup(content, 'html.parser') 14 15 # 世界确诊getAreaStat 16 listB = soup.find_all(name='script', attrs={"id": "getListByCountryTypeService2true"}) 17 18 world_messages = str(listB)[95:-21] 19 20 print(world_messages) 21 world_messages_json = json.loads(world_messages) 22 worldList = [] 23 now_time = datetime.datetime.now().strftime('%Y-%m-%d') 24 25 for k in range(len(world_messages_json)): 26 worldvalue = (now_time, 27 world_messages_json[k].get('countryType'), world_messages_json[k].get('continents'), 28 world_messages_json[k].get('provinceId'), world_messages_json[k].get('provinceName'), 29 world_messages_json[k].get('provinceShortName'), world_messages_json[k].get('cityName'), 30 world_messages_json[k].get('currentConfirmedCount'), world_messages_json[k].get('confirmedCount'), 31 world_messages_json[k].get('suspectedCount'), world_messages_json[k].get('curedCount'), 32 world_messages_json[k].get('deadCount'), world_messages_json[k].get('locationId'), 33 world_messages_json[k].get('countryShortCode'),) 34 worldList.append(worldvalue) 35 36 db = pymysql.connect("localhost", "root", "0000", "yiqing", charset='utf8') 37 cursor = db.cursor() 38 39 sql_world = "INSERT INTO world_map values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" 40 41 worldTuple = tuple(worldList) 42 print(worldTuple) 43 44 try: 45 cursor.executemany(sql_world, worldTuple) 46 db.commit() 47 except: 48 print('执行失败,进入回调2') 49 db.rollback() 50 51 db.close()
5系统使用说明书
首先进入系统
需要先进行注册:
提示注册成功:
使用刚刚注册的用户名密码就可登陆:
登录成功即进入如下界面即可实时查询:
我在这插入了一个操作小视频,也不知道为啥不可以显示
6 参考资料
[1] https://3g.163.com/news/article_cambrian/FBCUAKGF0521C9T8.html
[2] http://www.jingji.com.cn/shtml/jr/gdxw/110702.html
[3] https://article.itxueyuan.com/666gJq
[4] https://www.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6
[5] https://www.esri.com/en-us/disaster-response/request-assistance
[6] 参考博文:https://www.cnblogs.com/dd110343/p/12404756.html
[7] 参考博文: https://www.cnblogs.com/dd110343/p/12461824.html
7 附件说明
本文档要求的附件资料均压缩在“疫情统计图”压缩文件里。
Eclipse版本是2019
Python需导入的库有:pymysql、 requests、bs4
可执行文件“疫情统计图”将其解压就可运行,为了方便我把Python文件也放进去了,运行时吧Python文件单独出来就可
数据库需要后台建立才可完整运行。
项目源代码也均在压缩包里
注:其实地图可以没有必要有登录注册的,毕竟是人人可看的东西,但此处为了使系统完善强行加入了,登录界面也比较丑。