【IDEA】下将mondrian添加到JavaWeb

http://blog.csdn.net/evangel_z/article/details/29585571

过程参照以上博客,不过有一些与其中不同的地方。本文仅仅补充上面博客内容的不足。

1.下载IDEA,并且新建一个Web Project

我使用的IDEA版本是14.1.3,可能不同的版本创建Web Project的步骤不同,可以根据自己的版本去百度。这里需要注意的是IDEA新建的Web Project可能与eclipse中的Web Project的目录有点点不同,没有WebRoot或者WebContent是正常的。eclipse好像可以直接添加jpivot支持。但是IDEA需要下载额外的jar包

链接:https://pan.baidu.com/s/1gfTRzzX 密码:5dq5

我找不到原地址了。将这个5个包放到lib文件夹下就好了。

2.下载Mondrian的压缩包

Mondrian3.5的下载地址:https://nchc.dl.sourceforge.net/project/mondrian/mondrian/mondrian-3.5.0/mondrian-3.5.0.zip。

【IDEA】下将mondrian添加到JavaWeb_第1张图片


3.将压缩包中需要的部分加入到Web Project

1)进入到上图中的lib文件夹,找到mondrian.war

【IDEA】下将mondrian添加到JavaWeb_第2张图片

2)将mondrian.war解压,如下图

【IDEA】下将mondrian添加到JavaWeb_第3张图片

3)将圈中的文件复制到Web目录下,进入上图的WEB-INF文件夹,用里面web.xml替换你的工程的Web->WEB-INF的web.xml

【IDEA】下将mondrian添加到JavaWeb_第4张图片

4.下载jpivot的压缩包

下载地址:http://dl.download.csdn.net/down10/20111122/548f260dc8568245b1746d064f04155c.zip?response-content-disposition=attachment%3Bfilename%2A%3D%22utf8%27%27jpivot-1.8.0.zip%22&OSSAccessKeyId=9q6nvzoJGowBj4q1&Expires=1516177448&Signature=M%2BdOX76YhNt0Ppz%2BtRTZqF2xr1Q%3D&user=wkd_ywf&sourceid=3827309&sourcescore=3&isvip=0

这个是我登陆CSDN账号下载的,如果不使用这个里面的文件,将会导致servlet请求404页面的出现。

1)找到jpivot.war并解压

【IDEA】下将mondrian添加到JavaWeb_第5张图片

2)将下图圈中的文件复制到你的项目的WEB-INF中

【IDEA】下将mondrian添加到JavaWeb_第6张图片

5.数据库准备

因为我一直使用的是mysql数据库,这个例子我是用的也是Mysql数据库

1)JDBC driver下载

https://cdn.mysql.com//Downloads/Connector-J/mysql-connector-java-5.1.45.zip

2)IDEA引入jar,参考下面博客,很详细

http://blog.csdn.net/a153375250/article/details/50851049

引入之后不要忘记把这个jar文件复制到lib文件夹下

3)添加测试数据

  1. /**销售表*/  
  2. create table Sale (  
  3.     saleId int not null,  
  4.     proId int null,  
  5.     cusId int null,   
  6.     unitPrice float null,    --单价  
  7.     number int null,     --数量  
  8.     constraint PK_SALE primary key (saleId)  
  9. )  ;
  10.     /**用户表*/  
  11. create table Customer (  
  12.     cusId int not null,  
  13.     gender char(1) null,    --性别  
  14.     constraint PK_CUSTOMER primary key (cusId)  
  15. )  ;
  16. /**产品表*/  
  17. create table Product (  
  18.     proId int not null,  
  19.     proTypeId int null,  
  20.     proName varchar(32) null,  
  21.     constraint PK_PRODUCT primary key (proId)  
  22. )  ;
  23. /**产品类别表*/  
  24. create table ProductType (  
  25.     proTypeId int not null,  
  26.     proTypeName varchar(32) null,  
  27.     constraint PK_PRODUCTTYPE primary key (proTypeId)  
  28. )  ;

如果上面语句直接复制到数据库命令行出错,那就去掉注释部分。

  1. insert into Customer(cusId,gender) values(1,'F')  
  2. insert into Customer(cusId,gender) values(2,'M')  
  3. insert into Customer(cusId,gender) values(3,'M')  
  4. insert into Customer(cusId,gender) values(4,'F')  
  5. insert into producttype(proTypeId,proTypeName) values(1,'电器')  
  6. insert into producttype(proTypeId,proTypeName) values(2,'数码')  
  7. insert into producttype(proTypeId,proTypeName) values(3,'家具')  
  8. insert into product(proId,proTypeId,proName) values(1,1,'洗衣机')  
  9. insert into product(proId,proTypeId,proName) values(2,1,'电视机')  
  10. insert into product(proId,proTypeId,proName) values(3,2,'mp3')  
  11. insert into product(proId,proTypeId,proName) values(4,2,'mp4')  
  12. insert into product(proId,proTypeId,proName) values(5,2,'数码相机')  
  13. insert into product(proId,proTypeId,proName) values(6,3,'椅子')  
  14. insert into product(proId,proTypeId,proName) values(7,3,'桌子')  
  15. insert into sale(saleId,proId,cusId,unitPrice,number) values(1,1,1,340.34,2)  
  16. insert into sale(saleId,proId,cusId,unitPrice,number) values(2,1,2,140.34,1)  
  17. insert into sale(saleId,proId,cusId,unitPrice,number) values(3,2,3,240.34,3)  
  18. insert into sale(saleId,proId,cusId,unitPrice,number) values(4,3,4,540.34,4)  
  19. insert into sale(saleId,proId,cusId,unitPrice,number) values(5,4,1,80.34,5)  
  20. insert into sale(saleId,proId,cusId,unitPrice,number) values(6,5,2,90.34,26)  
  21. insert into sale(saleId,proId,cusId,unitPrice,number) values(7,6,3,140.34,7)  
  22. insert into sale(saleId,proId,cusId,unitPrice,number) values(8,7,4,640.34,28)  
  23. insert into sale(saleId,proId,cusId,unitPrice,number) values(9,6,1,140.34,29)  
  24. insert into sale(saleId,proId,cusId,unitPrice,number) values(10,7,2,740.34,29)  
  25. insert into sale(saleId,proId,cusId,unitPrice,number) values(11,5,3,30.34,28)  
  26. insert into sale(saleId,proId,cusId,unitPrice,number) values(12,4,4,1240.34,72)  
  27. insert into sale(saleId,proId,cusId,unitPrice,number) values(13,3,1,314.34,27)  
  28. insert into sale(saleId,proId,cusId,unitPrice,number) values(14,3,2,45.34,27)  

数据部分最好不要有中文,不然又要设置数据表某些地方UTF-8的属性,我是直接把那些中文换成了英文。


6.配置模式文件

test.jsp

<%@ taglib uri="http://www.tonbeller.com/jpivot" prefix="jp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<jp:mondrianQuery id="query01"
                  catalogUri="/WEB-INF/queries/test.xml"
                  jdbcDriver="com.mysql.jdbc.Driver"
                  jdbcUrl="jdbc:mysql://localhost:3306/mondrian"
                  jdbcUser="root"
                  jdbcPassword="123456"
        >
  select
  {[Measures].[numb],[Measures].[averPri],[Measures].[totalSale]} on columns,
  {([proType].[allPro],[cusGender].[allGender])}
  on rows
  from [Sales]
jp:mondrianQuery>

<c:set var="title01" scope="session">Salesc:set>span>
test.xml

xml version="1.0" encoding="UTF-8"?>
<Schema name="hello">
    <Cube name="Sales">
        
        <Table name="Sale" />
        
        <Dimension name="cusGender" foreignKey="cusId">
            <Hierarchy hasAll="true" allMemberName="allGender" primaryKey="cusId">
                <Table name="Customer">Table>
                <Level name="gender" column="gender">Level>
            Hierarchy>
        Dimension>
        
        <Dimension name="proType" foreignKey="proId">
            <Hierarchy hasAll="true" allMemberName="allPro" primaryKey="proId" primaryKeyTable="Product">
                <join leftKey="proTypeId" rightKey="proTypeId">
                    <Table name="Product" />
                    <Table name="ProductType">Table>
                join>
                <Level name="proTypeId" column="proTypeId"
                       nameColumn="proTypeName" uniqueMembers="true" table="ProductType" />
                <Level name="proId" column="proId" nameColumn="proName"
                       uniqueMembers="true" table="Product" />
            Hierarchy>
        Dimension>
        <Measure name="numb" column="number" aggregator="sum" datatype="Numeric" />
        <Measure name="totalSale" aggregator="sum" formatString="¥#,##0.00">
            
            <MeasureExpression>
                <SQL dialect="generic">(unitPrice*number)SQL>
            MeasureExpression>
        Measure>
        <CalculatedMember name="averPri" dimension="Measures">
            <Formula>[Measures].[totalSale] / [Measures].[numb]Formula>
            <CalculatedMemberProperty name="FORMAT_STRING" value="¥#,##0.00" />
        CalculatedMember>
    Cube>
Schema>
还是把配置模式文件代码贴一遍,test.jsp中修改数据库的用户名和密码。亲测可运行。



你可能感兴趣的:(mondrian)