14 结果导出与工作流调度

976-沈同学

发表文章数:64

热门标签

,
首页 » 大数据 » 正文

14 结果导出与工作流调度

1.结果导出

1.第一步:创建mysql数据库以及对应的数据库表

/*
SQLyog Ultimate v8.32 
MySQL - 5.6.22-log : Database - weblog
*********************************************************************
*/


/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`weblog` /*!40100 DEFAULT CHARACTER SET utf8 */;

USE `weblog`;

/*Table structure for table `dw_pvs_everyday` */

DROP TABLE IF EXISTS `dw_pvs_everyday`;

CREATE TABLE `dw_pvs_everyday` (
  `pvs` varchar(32) DEFAULT NULL,
  `month` varchar(16) DEFAULT NULL,
  `day` varchar(16) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/*Table structure for table `dw_pvs_everyhour_oneday` */

DROP TABLE IF EXISTS `dw_pvs_everyhour_oneday`;

CREATE TABLE `dw_pvs_everyhour_oneday` (
  `month` varchar(32) DEFAULT NULL,
  `day` varchar(32) DEFAULT NULL,
  `hour` varchar(32) DEFAULT NULL,
  `pvs` varchar(32) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/*Table structure for table `dw_pvs_referer_everyhour` */

DROP TABLE IF EXISTS `dw_pvs_referer_everyhour`;

CREATE TABLE `dw_pvs_referer_everyhour` (
  `refer_url` varchar(2048) DEFAULT NULL,
  `referer_host` varchar(64) DEFAULT NULL,
  `month` varchar(32) DEFAULT NULL,
  `day` varchar(32) DEFAULT NULL,
  `hour` varchar(32) DEFAULT NULL,
  `pv_referer_cnt` varchar(32) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

2.第二步:通过sqoop命令来进行导出

/export/servers/sqoop-1.4.6-cdh5.14.0/bin/sqoop export --connect jdbc:mysql://192.168.1.106:3306/weblog --username root --password admin --m 1  --export-dir /user/hive/warehouse/weblog.db/dw_pvs_everyday  --table dw_pvs_everyday  --input-fields-terminated-by '/001'

/export/servers/sqoop-1.4.6-cdh5.14.0/bin/sqoop export --connect jdbc:mysql://192.168.1.106:3306/weblog --username root --password admin --m 1  --export-dir /user/hive/warehouse/weblog.db/dw_pvs_everyhour_oneday/datestr=20130918  --table dw_pvs_everyhour_oneday  --input-fields-terminated-by '/001' 

/export/servers/sqoop-1.4.6-cdh5.14.0/bin/sqoop export --connect jdbc:mysql://192.168.1.106:3306/weblog --username root --password admin --m 1  --export-dir /user/hive/warehouse/weblog.db/dw_pvs_referer_everyhour/datestr=20130918  --table dw_pvs_referer_everyhour  --input-fields-terminated-by '/001' 

2.工作流的调度:

将我们所有的任务串起来,定时执行
1、flume数据的采集 flume一直在采集 不需要定时执行
2、数据的清洗,表模型三个mr的程序 需要定时执行
第一个:mr清洗数据
第二个:pageview表模型
第三个:visit表模型
3、hive建表加载数据
每天产生的数据,都要定时的加载到hive的对应的分区表里面去
4、数据分析的hql语句
自己开发的hql语句写到脚本里面定时开发执行
5、数据导出
sqoop数据导出

1.job

type=command
command=/export/servers/hadoop-2.6.0-cdh5.14.0/bin/hadoop jar weblogparser.jar cn.itcast.bigdata.weblog.pre.WeblogPreProcess

2.job

type=command
command=/export/servers/hadoop-2.6.0-cdh5.14.0/bin/hadoop jar weblogparser.jar cn.itcast.bigdata.weblog.clickstream.ClickStreamPageView
dependencies=1

3.job

type=command
command=/export/servers/hadoop-2.6.0-cdh5.14.0/bin/hadoop jar weblogparser.jar cn.itcast.bigdata.weblog.clickstream.ClickStreamVisit
dependencies=2

4.job

type=command
command=sh 4.sh
dependencies=3

4.sh

#!/bin/bash

#set java env
export JAVA_HOME=/export/servers/jdk1.8.0_141
export JRE_HOME={JAVA_HOME}/jre
export CLASSPATH=.:{JAVA_HOME}/lib:{JRE_HOME}/lib
export PATH={JAVA_HOME}/bin:PATH

#set hadoop env
export HADOOP_HOME=/export/servers/hadoop-2.6.0-cdh5.14.0
export PATH={HADOOP_HOME}/bin:{HADOOP_HOME}/sbin:PATH

#获取时间信息
day_01=`date -d'-1 day' +%Y%m%d`
syear=`date --date=day_01 +%Y`
smonth=`date --date=day_01 +%m`
sday=`date --date=day_01 +%d`

#预处理输出结果(raw)目录
log_pre_output="/weblog/'day_01'/weblogPreOut"
#点击流clickStream模型预处理程序输出目录
pageView="/weblog/'day_01'/pageViewOut"
#点击流visit模型预处理程序输出目录
visit="/weblog/'day_01'/clickStreamVisit"

#目标hive表
ods_weblog_origin="weblog.ods_weblog_origin"
ods_click_pageviews="weblog.ods_click_pageviews"
ods_click_stream_visit="weblog.ods_click_stream_visit"

#导入数据到weblog.ods_weblog_origin
HQL_origin="load data inpath 'log_pre_output' overwrite into tableods_weblog_origin partition(datestr='day_01')"
echoHQL_origin 
/export/servers/hive-1.1.0-cdh5.14.0/bin/hive -e "HQL_origin"




#导入点击流模型pageviews数据到
HQL_pvs="load data inpath 'pageView' overwrite into table ods_click_pageviews partition(datestr='day_01')"
echoHQL_pvs 
/export/servers/hive-1.1.0-cdh5.14.0/bin/hive -e "HQL_pvs"

#导入点击流模型visit数据到
HQL_vst="load data inpath 'visit' overwrite into table ods_click_stream_visit partition(datestr='day_01')"
echo HQL_vst 
/export/servers/hive-1.1.0-cdh5.14.0/bin/hive -e "HQL_vst"

5.job

type=command
command=/export/servers/hive-1.1.0-cdh5.14.0/bin/hive -f "5.sql"
dependencies=4

5.sql

create database if not exist weblog;
use weblog;

-- 1.1.1 计算该处理批次(一天)中的各小时pvs
drop table if exists dw_pvs_everyhour_oneday;
create table if not exists dw_pvs_everyhour_oneday(month string,day string,hour string,pvs bigint) partitioned by(datestr string);

insert  into table dw_pvs_everyhour_oneday partition(datestr='20130918')
select a.month as month,a.day as day,a.hour as hour,count(*) as pvs from ods_weblog_detail a
where  a.datestr='20130918' group by a.month,a.day,a.hour;

-- 计算每天的pvs
drop table if exists dw_pvs_everyday;
create table if not  exists dw_pvs_everyday(pvs bigint,month string,day string);

insert into table dw_pvs_everyday select count(*) as pvs,a.month as month,a.day as day from ods_weblog_detail a group by a.month,a.day;

-- 统计每小时各来访url产生的pv量,查询结果存入:( "dw_pvs_referer_everyhour" )

drop table if exists dw_pvs_referer_everyhour;
create table if not exists dw_pvs_referer_everyhour (referer_url string,referer_host string,month string,day string,hour string,pv_referer_cnt bigint) partitioned by(datestr string);

insert into table dw_pvs_referer_everyhour partition(datestr='20130918') select http_referer,ref_host,month,day,hour,count(1) as pv_referer_cnt from ods_weblog_detail  group by http_referer,ref_host,month,day,hour  having ref_host is not null order by hour asc,day asc,month asc,pv_referer_cnt desc;



-- 统计每小时各来访host的产生的pv数并排序
drop table if exists dw_pvs_refererhost_everyhour;
create table if not exists dw_pvs_refererhost_everyhour(ref_host string,month string,day string,hour string,ref_host_cnts bigint) partitioned by(datestr string);

insert into table dw_pvs_refererhost_everyhour partition(datestr='20130918') select ref_host,month,day,hour,count(1) as ref_host_cnts from ods_weblog_detail  group by ref_host,month,day,hour  having ref_host is not null order by hour asc,day asc,month asc,ref_host_cnts desc;

6.job

type=command
command=sh 6.sh
dependencies=5

6.sh

#!/bin/bash

#数据导出
/export/servers/sqoop-1.4.6-cdh5.14.0/bin/sqoop export --connect jdbc:mysql://192.168.176.26:3306/weblog --username root --password admin --m 1  --export-dir /user/hive/warehouse/weblog.db/dw_pvs_everyday  --table dw_pvs_everyday  --input-fields-terminated-by '/001'

#数据导出
/export/servers/sqoop-1.4.6-cdh5.14.0/bin/sqoop export --connect jdbc:mysql://192.168.176.26:3306/weblog --username root --password admin --m 1  --export-dir /user/hive/warehouse/weblog.db/dw_pvs_everyhour_oneday/datestr=20130918  --table dw_pvs_everyhour_oneday  --input-fields-terminated-by '/001' 

#数据导出
/export/servers/sqoop-1.4.6-cdh5.14.0/bin/sqoop export --connect jdbc:mysql://192.168.176.26:3306/weblog --username root --password admin --m 1  --export-dir /user/hive/warehouse/weblog.db/dw_pvs_referer_everyhour/datestr=20130918  --table dw_pvs_referer_everyhour  --input-fields-terminated-by '/001' 

3.echarts数据可视化

第一步:数据导入准备

/*
SQLyog Ultimate v8.32 
MySQL - 5.6.22-log : Database - web_log_view
*********************************************************************
*/

/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`web_log_view` /*!40100 DEFAULT CHARACTER SET utf8 */;

USE `web_log_view`;

/*Table structure for table `t_avgpv_num` */

DROP TABLE IF EXISTS `t_avgpv_num`;

CREATE TABLE `t_avgpv_num` (
  `id` int(11) DEFAULT NULL,
  `dateStr` varchar(255) DEFAULT NULL,
  `avgPvNum` decimal(6,2) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

/*Data for the table `t_avgpv_num` */

insert  into `t_avgpv_num`(`id`,`dateStr`,`avgPvNum`) values (1,'20130919','13.40'),(2,'20130920','17.60'),(3,'20130921','15.20'),(4,'20130922','21.10'),(5,'20130923','16.90'),(6,'20130924','18.10'),(7,'20130925','18.60');

/*Table structure for table `t_flow_num` */

DROP TABLE IF EXISTS `t_flow_num`;

CREATE TABLE `t_flow_num` (
  `id` int(11) DEFAULT NULL,
  `dateStr` varchar(255) DEFAULT NULL,
  `pVNum` int(11) DEFAULT NULL,
  `uVNum` int(11) DEFAULT NULL,
  `iPNum` int(11) DEFAULT NULL,
  `newUvNum` int(11) DEFAULT NULL,
  `visitNum` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

/*Data for the table `t_flow_num` */

insert  into `t_flow_num`(`id`,`dateStr`,`pVNum`,`uVNum`,`iPNum`,`newUvNum`,`visitNum`) values (1,'20131001',4702,3096,2880,2506,3773),(2,'20131002',7528,4860,4435,4209,5937),(3,'20131003',7286,4741,4409,4026,5817),(4,'20131004',6653,5102,4900,2305,4659),(5,'20131005',5957,4943,4563,3134,3698),(6,'20131006',7978,6567,6063,4417,4560),(7,'20131007',6666,5555,4444,3333,3232);

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

第二步:创建maven web工程并导入jar包

<packaging>war</packaging>

<dependencies>
    <!-- Spring -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>4.2.4.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>4.2.4.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>4.2.4.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>4.2.4.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aspects</artifactId>
      <version>4.2.4.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jms</artifactId>
      <version>4.2.4.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</artifactId>
      <version>4.2.4.RELEASE</version>
    </dependency>
    <!-- Mybatis -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.2.8</version>
    </dependency>
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>1.2.2</version>
    </dependency>
    <dependency>
      <groupId>com.github.miemiedev</groupId>
      <artifactId>mybatis-paginator</artifactId>
      <version>1.2.15</version>
    </dependency>
    <!-- MySql -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.32</version>
    </dependency>
    <!-- 连接池 -->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>1.0.9</version>
    </dependency>
    <!-- JSP相关 -->
    <dependency>
      <groupId>jstl</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.0</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.4.2</version>
    </dependency>
  </dependencies>

  <build>
    <finalName>${project.artifactId}</finalName>
    <resources>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.properties</include>
          <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
      </resource>
      <resource>
        <directory>src/main/resources</directory>
        <includes>
          <include>**/*.properties</include>
          <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
      </resource>
    </resources>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.2</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>

      <!-- 配置Tomcat插件 -->
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <path>/</path>
          <port>8080</port>
        </configuration>
      </plugin>
    </plugins>
  </build>

14 结果导出与工作流调度

第三步:配置SqlMapConfig.xml(mybatis)

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <settings>
        <!-- 打印查询语句 -->
        <setting name="logImpl" value="STDOUT_LOGGING" />
    </settings>
</configuration>

第四步:配置ApplicationContext.xml (spring)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:c="http://www.springframework.org/schema/c"
       xsi:schemaLocation="
	   		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!-- spring 里面要配置哪些东西
    包扫描
    数据库连接池
    事务管理
    与mybatis的整合  这里面有两个配置
 -->
    <!-- 不要放大包扫描的路径-->
    <context:component-scan base-package="cn.itcast.weblog.service"/>
    <!--数据库连接池-->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://192.168.1.26:3306/web_log_view?characterEncoding=utf-8"></property>
        <property name="username" value="root"></property>
        <property name="password" value="123456"></property>
    </bean>

    <!-- 事务控制
        两大类:
            编程式事务
            申明式事务:
                xml方式管理事务
                使用注解的方式 (true)
    -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <!-- 配置我们使用注解的方式实现事务的管理 在service层加一个注解 @Transactional-->
    <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>
    <!--与mybatis的整合-->
    <bean class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="configLocation" value="classpath:sqlMapConfig.xml"></property>
        <!--配置我们mybais每个表对应的xml的位置-->
        <property name="mapperLocations" value="classpath:mappers/*.xml"></property>
    </bean>
    <!--扫描所有接口,产生代理类-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="cn.itcast.weblog.mapper"></property>
    </bean>
</beans>

第五步:配置springMVC.xml (springMVC)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:task="http://www.springframework.org/schema/task"
       xsi:schemaLocation="
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd">

    <!--  配置包扫描 -->
    <context:component-scan base-package="cn.itcast.weblog.controller"></context:component-scan>

    <!--  使用mvc的注解驱动开发-->
    <mvc:annotation-driven/>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>

</beans>

第六步:配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
    <display-name>crm</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
        <welcome-file>index.action</welcome-file>
    </welcome-file-list>

    <!-- 配置contextLoadListener -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

    <!-- Bootstraps the root web application context before servlet initialization -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>



    <!-- 配置dispatcherServlet -->
    <!-- The front controller of this Spring Web application, responsible for handling all application requests -->
    <servlet>
        <servlet-name>springDispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:springMVC.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Map all requests to the DispatcherServlet for handling -->
    <servlet-mapping>
        <servlet-name>springDispatcherServlet</servlet-name>
        <url-pattern>*.action</url-pattern>
    </servlet-mapping>




    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>utf-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


</web-app>

第七步:拷贝我们准备好的资源文件到项目中

14 结果导出与工作流调度

第八步:配置IDEA使用tomcat插件访问我们的项目

14 结果导出与工作流调度
14 结果导出与工作流调度
14 结果导出与工作流调度
controller–>service–>mapper
14 结果导出与工作流调度

第九步:开发controller层

package cn.itcast.weblog.controller;

import cn.itcast.weblog.pojo.AvgPvNumReturnPojo;
import cn.itcast.weblog.pojo.FlowNum;
import cn.itcast.weblog.pojo.FlowNumReturnPojo;
import cn.itcast.weblog.service.AvgPvNumService;
import cn.itcast.weblog.service.FlowNumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class IndexController {

    @RequestMapping("/index.action")
    public String skipToIndex(){
        return "index";
    }

    @Autowired
    private AvgPvNumService avgPvNumService;

    @RequestMapping("/avgPvNum.action")
    @ResponseBody
    public AvgPvNumReturnPojo getAllPvNum(){
        AvgPvNumReturnPojo avgPvNumReturnPojo = avgPvNumService.getAllPvNum();
        return avgPvNumReturnPojo;
    }

    @Autowired
    private FlowNumService flowNumService;

    @RequestMapping("/flowNum.action")
    @ResponseBody
    public FlowNumReturnPojo getFlowNum(){
        FlowNumReturnPojo flowNumReturnPojo = flowNumService.getAllFlowNum();
        return flowNumReturnPojo;
    }

}

第十步:开发service层

AvgNum

package cn.itcast.weblog.service;

import cn.itcast.weblog.pojo.AvgPvNumReturnPojo;

public interface AvgPvNumService {
    AvgPvNumReturnPojo getAllPvNum();
}
package cn.itcast.weblog.service;

import cn.itcast.weblog.mapper.AvgPvNumMapper;
import cn.itcast.weblog.pojo.AvgPvNum;
import cn.itcast.weblog.pojo.AvgPvNumReturnPojo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class AvgPvNumServiceImpl implements AvgPvNumService {

    @Autowired
    private AvgPvNumMapper avgPvNumMapper;

    @Override
    public AvgPvNumReturnPojo getAllPvNum() {
        AvgPvNumReturnPojo avgPvNumReturnPojo = new AvgPvNumReturnPojo();
        List<String> dateStr = new ArrayList<String>();
        List<String> data = new ArrayList<String>();

        List<AvgPvNum> avgPvNumList = avgPvNumMapper.getAllPvNum();
        for (AvgPvNum avgPvNum : avgPvNumList) {
            dateStr.add(avgPvNum.getDateStr());
            data.add(avgPvNum.getAvgPvNum());
        }
        avgPvNumReturnPojo.setData(data);
        avgPvNumReturnPojo.setDates(dateStr);

        return avgPvNumReturnPojo;
    }
}

FlowNum

package cn.itcast.weblog.service;

import cn.itcast.weblog.pojo.FlowNumReturnPojo;

public interface FlowNumService {
    FlowNumReturnPojo getAllFlowNum();
}
package cn.itcast.weblog.service;

import cn.itcast.weblog.mapper.FlowNumMapper;
import cn.itcast.weblog.pojo.FlowNum;
import cn.itcast.weblog.pojo.FlowNumReturnPojo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class FlowNumServiceImpl implements FlowNumService {

    @Autowired
    private FlowNumMapper flowNumMapper;
    
    @Override
    public FlowNumReturnPojo getAllFlowNum() {
        FlowNumReturnPojo flowNumReturnPojo = new FlowNumReturnPojo();
        ArrayList<String> dates = new ArrayList<String>();
        ArrayList<Integer> uvs = new ArrayList<Integer>();
        ArrayList<Integer> new_uvs = new ArrayList<Integer>();

        List<FlowNum> flowNumList = flowNumMapper.getAllFlowNum();
        for (FlowNum flowNum : flowNumList) {
            dates.add(flowNum.getDateStr());
            uvs.add(flowNum.getnVNum());
            new_uvs.add(flowNum.getNewUvNum());
        }
        flowNumReturnPojo.setDates(dates);
        flowNumReturnPojo.setUvs(uvs);
        flowNumReturnPojo.setUvs(new_uvs);

        return flowNumReturnPojo;
    }
}

第十一步:开发mapper层的xml以及接口

package cn.itcast.weblog.mapper;

import cn.itcast.weblog.pojo.AvgPvNum;

import java.util.List;

public interface AvgPvNumMapper {
    List<AvgPvNum> getAllPvNum();
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.itcast.weblog.mapper.AvgPvNumMapper" >
<select id="getAllPvNum" resultType="cn.itcast.weblog.pojo.AvgPvNum">
    select * from t_avgpv_num;
</select>
</mapper>
package cn.itcast.weblog.mapper;

import cn.itcast.weblog.pojo.FlowNum;

import java.util.List;

public interface FlowNumMapper {
    List<FlowNum> getAllFlowNum();
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="cn.itcast.weblog.mapper.FlowNumMapper" >
    <select id="getAllFlowNum" resultType="cn.itcast.weblog.pojo.FlowNum">
        select * from t_flow_num;
    </select>
</mapper>

第十二步:pojo类

package cn.itcast.weblog.pojo;

public class AvgPvNum {
    private Integer id;
    private String dateStr;
    private String avgPvNum;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getDateStr() {
        return dateStr;
    }

    public void setDateStr(String dateStr) {
        this.dateStr = dateStr;
    }

    public String getAvgPvNum() {
        return avgPvNum;
    }

    public void setAvgPvNum(String avgPvNum) {
        this.avgPvNum = avgPvNum;
    }
}
package cn.itcast.weblog.pojo;

import java.util.List;
//POJO(Plain Ordinary Java Object)意思是普通的java对象 ,没有继承任何类、实现任何接口、也没有包含特殊的注解
public class AvgPvNumReturnPojo {
    private List<String> dates;
    private List<String> data;

    public List<String> getDates() {
        return dates;
    }

    public void setDates(List<String> dates) {
        this.dates = dates;
    }

    public List<String> getData() {
        return data;
    }

    public void setData(List<String> data) {
        this.data = data;
    }
}
package cn.itcast.weblog.pojo;

public class FlowNum {
    private Integer id;
    private String dateStr;
    private Integer pVNum;
    private Integer nVNum;
    private Integer iPNum;
    private Integer newUvNum;
    private Integer visitNum;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getDateStr() {
        return dateStr;
    }

    public void setDateStr(String dateStr) {
        this.dateStr = dateStr;
    }

    public Integer getpVNum() {
        return pVNum;
    }

    public void setpVNum(Integer pVNum) {
        this.pVNum = pVNum;
    }

    public Integer getnVNum() {
        return nVNum;
    }

    public void setnVNum(Integer nVNum) {
        this.nVNum = nVNum;
    }

    public Integer getiPNum() {
        return iPNum;
    }

    public void setiPNum(Integer iPNum) {
        this.iPNum = iPNum;
    }

    public Integer getNewUvNum() {
        return newUvNum;
    }

    public void setNewUvNum(Integer newUvNum) {
        this.newUvNum = newUvNum;
    }

    public Integer getVisitNum() {
        return visitNum;
    }

    public void setVisitNum(Integer visitNum) {
        this.visitNum = visitNum;
    }
}
package cn.itcast.weblog.pojo;

import java.util.List;

public class FlowNumReturnPojo {
    private List<String> dates;
    private List<Integer> uvs;
    private List<Integer> new_uvs;

    public List<String> getDates() {
        return dates;
    }

    public void setDates(List<String> dates) {
        this.dates = dates;
    }

    public List<Integer> getUvs() {
        return uvs;
    }

    public void setUvs(List<Integer> uvs) {
        this.uvs = uvs;
    }

    public List<Integer> getNew_uvs() {
        return new_uvs;
    }

    public void setNew_uvs(List<Integer> new_uvs) {
        this.new_uvs = new_uvs;
    }
}

拜师教育学员文章:作者:976-沈同学, 转载或复制请以 超链接形式 并注明出处 拜师资源博客
原文地址:《14 结果导出与工作流调度》 发布于2020-05-19

分享到:
赞(0) 打赏

评论 抢沙发

评论前必须登录!

  注册



长按图片转发给朋友

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

Vieu3.3主题
专业打造轻量级个人企业风格博客主题!专注于前端开发,全站响应式布局自适应模板。

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

Q Q 登 录
微 博 登 录