javascript Date format(js日期格式化)

    <script>
    Date.prototype.pattern=function(fmt) {         
        var o = {         
            "M+" : this.getMonth()+1, //月份         
            "d+" : this.getDate(), //日         
            "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时         
            "H+" : this.getHours(), //小时         
            "m+" : this.getMinutes(), //分         
            "s+" : this.getSeconds(), //秒         
            "q+" : Math.floor((this.getMonth()+3)/3), //季度         
            "S" : this.getMilliseconds() //毫秒         
            };         
        var week = {         
            "0" : "/u65e5",         
            "1" : "/u4e00",         
            "2" : "/u4e8c",         
            "3" : "/u4e09",         
            "4" : "/u56db",         
            "5" : "/u4e94",         
            "6" : "/u516d"        
            };         
        if(/(y+)/.test(fmt)){         
            fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));         
        }         
        if(/(E+)/.test(fmt)){         
            fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "/u661f/u671f" : "/u5468") : "")+week[this.getDay()+""]);         
        }         
        for(var k in o){         
            if(new RegExp("("+ k +")").test(fmt)){         
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));         
            }         
        }         
        return fmt;         
    }       

    var date = new Date();      
    window.alert(date.pattern("yyyyMMddhhmmss"));
</script>

css样式的覆盖顺序

css样式的层叠

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="style.css">
    <style>
     p {
        color: red;
     }
    </style>

    <title>index</title>
</head>
<body>
    <div>
        <p id ="pid" class="pclass" style="color: grey;">
            hello this is p tag!
        </p>
    </div>
</body>
</h3tml>

style.css

p {
    color: green;
    font-size: 18px;
}

#pid {
     color: orange; 
}

.pclass {
    color: black;
}

div p.pclass {
    color: blue
}

样式的优先级(由高到低):

1. 内联样式                    style="color: grey;"
2. id选择器                     #pid  color: orange;
3. 路径下样式选择器       div p.pclass color: blue
4. 样式选择器                 .pclass color: black; 
5. 路径下 tag标签选择器        div > p
6. tag标签选择器               p      color: black;
7. 浏览器默认样式

获取最准确的样式,可以在chrome下F12,Copy CSS path

ant构建java项目

Apache Ant,是一个将软件编译、测试、部署等步骤联系在一起加以自动化的一个工具,大多用于Java环境中的软件开发。由Apache软件基金会所提供。

1. 用java命令编译,打包java文件

  • 无包结构的java源代码
public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello World, this is a class without package");
    }
}

javac编译

E:\ant\SpaceMgt\src>javac Hello.java

E:\ant\SpaceMgt\src>java Hello
Hello World, this is a class without package

这时会发现在当前目录下会出现 Hello.class文件,说明java代码已经编译成字节码class

  • 有包结构的java源代码
package com.rick;

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello World, this is a class with package");
    }
}

javac编译

E:\ant\SpaceMgt\src>javac -d . Hello.java

E:\ant\SpaceMgt\src>java com.rick.Hello
Hello World, this is a class with package

这时会发现在当前目录下新建目录com/rick/Hello.class文件,说明java代码已经编译成字节码class,同时在包中

jar打包

E:\ant\SpaceMgt\src>jar -cvf hello.jar com
已添加清单
正在添加: com/(输入 = 0) (输出 = 0)(存储了 0%)
正在添加: com/rick/(输入 = 0) (输出 = 0)(存储了 0%)
正在添加: com/rick/Hello.class(输入 = 454) (输出 = 317)(压缩了 30%)

运行jar文件
如果这个是个可执行的jar,可以这么运行

E:\ant\SpaceMgt\src>java -jar hello.jar
hello.jar中没有主清单属性

因为hello.jar不是可执行的jar,所以会抛出错误:hello.jar中没有主清单属性。可以通过以下两种方式执行jar文件中的main方法

E:\ant\SpaceMgt\src>set classpath=hello.jar

E:\ant\SpaceMgt\src>java com.rick.Hello
Hello World, this is a class with package

E:\ant\SpaceMgt\src>java -cp hello.jar com.rick.Hello
Hello World, this is a class with package

如何让jar成为可执行的jar呢?编辑jar中META-INF/MANIFEST.MF,添加一行

Main-Class: com.rick.Hello

2. 用ant编译,打包jar文件

检查ant环境

E:\ant\SpaceMgt\src>ant -version
Apache Ant(TM) version 1.9.6 compiled on June 29 2015

项目的目录结构:

    SpaceMgt
        build
        src
            |com
            |rick
                |Hello.java
        build.xml        

ant需要配置文件build.xml

<project basedir="." default="publish" name="SpaceMgt">
    <target name="publish">
         <javac srcdir="src" destdir="build">

         </javac>
         <jar basedir="build" destfile="build/jar/hello.jar"/>

    </target>
</project>

执行ant命令

E:\ant\SpaceMgt>ant
Buildfile: E:\ant\SpaceMgt\build.xml

publish:
    [javac] E:\ant\SpaceMgt\build.xml:3: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
      [jar] Building jar: E:\ant\SpaceMgt\build\jar\hello.jar

BUILD SUCCESSFUL
Total time: 0 seconds

完成之后,你会看见build/jar/hello.jar

3. 用ant编译,打包war文件

项目的目录结构:

    SpaceMgt
        build
        src
            |com
            |rick
                |Hello.java
        WebRoot
            |WEB-INF
                lib
                web.xml
            |index.jsp
        build.xml        

build.xml

<project basedir="." default="publish" name="SpaceMgt">
    <target name="publish">
        <property name="build.dest" value="build/war/SpaceMgt"/>    

         <mkdir dir="${build.dest}/WEB-INF/classes"/>

         <copy todir="${build.dest}">  
            <fileset dir="WebRoot"/>  
         </copy>  

         <javac srcdir="src" destdir="${build.dest}/WEB-INF/classes">
         </javac>

         <war warfile="build/war/SpaceMgt.war" basedir="${build.dest}" webxml="${build.dest}/WEB-INF/web.xml"/>  

    </target>
</project>

执行ant

E:\ant\SpaceMgt>ant
Buildfile: E:\ant\SpaceMgt\build.xml

publish:
    [javac] E:\ant\SpaceMgt\build.xml:11: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
      [war] Building war: E:\ant\SpaceMgt\build\war\SpaceMgt.war

BUILD SUCCESSFUL
Total time: 0 seconds

将SpaceMgt.war放入tomcat webapp下,启动tomcat访问url:http://localhost:8080/SpaceMgt/index.jsp

3. ant其他功能

通过ant不仅可以编译打包,还能上传文件到ftp/scp

example:

 <ftp server="ftp.apache.org"
       userid="anonymous"
       password="me@myorg.com">
    <fileset dir="htdocs/manual"/>
  </ftp>

  <scp file="myfile.txt" todir="user:password@somehost:/home/chuck"/>

  ....

具体可参照:

  1. http://ant.apache.org/manual/Tasks/scp.html
  2. http://ant.apache.org/manual/Tasks/ftp.html

注意这里需要一些jar的支持,ftp需要common-net.jar,scp需要jsch-0.1.40.jar
下载jar到ANT_HOME/lib目录下,并在build.xml指定classpath

<property name="ANT_HOME" value="D:\develop\apache-ant-1.9.6"/>

<path id="classpath">
    <fileset dir="${ANT_HOME}">
        <include name="**/*.jar"/>
    </fileset>
</path>

ant常见命令可参考:http://www.cnblogs.com/xionghui/archive/2012/03/13/2393679.html

Oracle一列的多行数据拼成一行显示字符

转自http://zhoujingxian.iteye.com/blog/1774235

Oracle一列的多行数据拼成一行显示字符,例如:
id name
========
1 aa
2 bb
3 cc

要的结果是”aa,bb,cc”

oracle 提供了两个函数WMSYS.WM_CONCATListAgg函数。

WMSYS.WM_CONCAT函数

select WMSYS.WM_CONCAT(a.name) from user a

这样的话,查询出的结果:”aa,bb,cc”

分隔符如果不需要用英文的逗号,需要改成别的符号比如分号的,可以用下面的方法替换下:

select replace(WMSYS.WM_CONCAT(a.name),',',';') from user a

结果:”aa;bb;cc”

ListAgg函数

listagg函数的语法结构如下:
LISTAGG( [,]) WITHIN GROUP (ORDER BY ) [OVER (PARTITION BY )]
listagg虽然是聚合函数,但可以提供分析功能(比如可选的OVER()子句)。使用listagg中,下列中的元素是必须的:

  • 需要聚合的列或者表达式
  • WITH GROUP 关键词
  • 分组中的ORDER BY子句

例子:

DEPTNO ENAME
============
   10 CLARK
   10 KING
   10 MILLER
   20 ADAMS
   20 FORD
   20 JONES

按照DEPTNO字段分组,对结果集进行字符串聚合,结果如下:

DEPTNO AGGREGATED_ENAMES
=======================
10 CLARK,KING,MILLER
20 ADAMS,FORD,JONES

SQL:

SELECT deptno,LISTAGG(ename, ',') WITHIN GROUP (ORDER BY ename) AS employees FROM  emp GROUP BY deptno;