作者归档:Rick

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;

IDEA开发 Maven打包可执行的jar JSmooth转exe文件

这个文章主要解决这样几个问题

  1. IDEA如何用Maven管理项目
  2. Maven如何打包成可执行jar
  3. JSmooth转jar为exe文件

IDEA如何用Maven管理项目



Maven如何打包成可执行jar

在pom.xml中配置
com.rick.client.App是main函数所在的类

<plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>com.rick.client.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>assembly</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>ibiblio.org</id>
            <name>ibiblio Mirror of http://repo1.maven.org/maven2/</name>
            <url>http://mirrors.ibiblio.org/pub/mirrors/maven2</url>
        </repository>
    </repositories>

执行mvn命令,打包可执行jar

E:\p4v_location\watsonsTNA\fine>mvn assembly:assembly
E:\p4v_location\watsonsTNA\fine\target>java -jar exe-1.0-SNAPSHOT.jar

JSmooth转jar为exe文件



Python高级编程使用__slots__

这这一节主要是动态为对象/实例添加属性和方法

代码如下

from types import MethodType

#这是外部方法1
def set_name(self, name):
    self.name = name


#这是外部方法2
def set_score(self, score):
    self.score = score    

class Student(object):
    __slots__ = ('name')

    def set_age(self, age):
        self.age = age

stu = Student();
stu.age = 10
stu.set_age(20)

#给实例绑定一个方法,此处绑定到实例stu,对其他实例不起作用
stu.set_name = MethodType(set_name, stu) # 给实例绑定一个方法
stu.set_name('Rick')

print(stu.name)    

#给类绑定一个方法,所有的实例都可以使用
Student.set_score = MethodType(set_score, Student)
stu.set_score(99.5)
print(stu.score)

使用slots

但是,如果我们想要限制实例的属性怎么办?比如,只允许对Student实例添加namescore属性

class Student(object):
    __slots__ = ('name', 'store') # 用tuple定义允许绑定的属性名称

如果有不允许的属性,将会抛出异常

F:\python>python slots.py
Traceback (most recent call last):
  File "slots.py", line 18, in <module>
    stu.age = 10
AttributeError: 'Student' object has no attribute 'age'

Note:
使用__slots__要注意,__slots__定义的属性仅对当前类实例起作用,对继承的子类是不起作用的: