2017-12-08 22:58:09   Visit  10

1 select delete

2017-12-08 15:39:51   Visit  14

JavaScript 生成 SVG 圆角矩形 PATH

  var length = 12 * text.length; //横向直线长度
     
          var height = 28;//高度
          var r = 10;//圆角半径
          var half_h = height/2;
          var s_half_h = half_h - r;
          var H_all = length + r + r;//横向总长度
          var path = "M0 0 V " + s_half_h + " "; 
          path += "Q 0 "+ half_h+" "+ r +" "+half_h+" H " + (length  + r) + " ";
          path += "Q " + H_all + " " + half_h + " " + H_all + " " + s_half_h +" V -" + s_half_h + " ";
          path += "Q " + H_all + " -" + half_h + " " + (H_all-r) + " -" + half_h +" H " + r + " "; 
          path += "Q 0 -" + half_h + " 0 -" + s_half_h +" V " + 0 + " Z"; 
2017-11-08 16:52:19   Visit  40

Tomcat、memcached、Nginx环境下共享session

Tomcat 配置

<Manager       
        className="de.javakaffee.web.msm.MemcachedBackupSessionManager" 
        memcachedNodes="n1:127.0.0.1:11211" 
        sticky="false" 
        sessionBackupAsync="false" 
        copyCollectionsForSerialization="false" 
        
        transcoderFactoryClass="de.javakaffee.web.msm.JavaSerializationTranscoderFactory" 
      />

memcachedNodes 多个节点使用英文逗号隔开。

memcached相关jar


jar放在Tomcat lib目录下。

2017-11-03 18:16:11   Visit  43
        location /  {
            proxy_pass http://tomcat_server; 
            proxy_set_header Host $http_host; 
            proxy_set_header X-Forward-For $remote_addr; 
            proxy_connect_timeout       10;
            proxy_read_timeout          10;
            proxy_send_timeout          10;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
2017-10-30 15:44:36   Visit  61

在java中如何对一组数据做排序?

Java原生提供了这一支持,所以我们没必要在开发中再造轮子。这里我们使用的是Comparable接口。
要对比的对象需要实现Comparable接口,并实现一个方法:

compareTo(<T>)

该方法返回1或者-1(最好是互为反数)。

排序

Collections.sort(list);  

下面是我的代码

@Entity
@Table(name = "t_s_dddepart", schema = "")
@SuppressWarnings("serial")
public class DingDingDepart     implements java.io.Serializable , Comparable<DingDingDepart> {
    /**id*/
    private java.lang.Integer id;
    /**name*/
    @Excel(name="name")
    private java.lang.String name;
    /**parentid*/
    @Excel(name="parentid")
    private java.lang.Integer parentid;
    
    /**
     *方法: 取得java.lang.Integer
     *@return: java.lang.Integer  id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name ="ID",nullable=false,length=13)
    public java.lang.Integer getId(){
        return this.id;
    }

    /**
     *方法: 设置java.lang.Integer
     *@param: java.lang.Integer  id
     */
    public void setId(java.lang.Integer id){
        this.id = id;
    }
    /**
     *方法: 取得java.lang.String
     *@return: java.lang.String  name
     */
    @Column(name ="NAME",nullable=true,length=255)
    public java.lang.String getName(){
        return this.name;
    }

    /**
     *方法: 设置java.lang.String
     *@param: java.lang.String  name
     */
    public void setName(java.lang.String name){
        this.name = name;
    }
    /**
     *方法: 取得java.lang.Integer
     *@return: java.lang.Integer  parentid
     */
    @Column(name ="PARENTID",nullable=true,length=13)
    public java.lang.Integer getParentid(){
        return this.parentid;
    }

    /**
     *方法: 设置java.lang.Integer
     *@param: java.lang.Integer  parentid
     */
    public void setParentid(java.lang.Integer parentid){
        this.parentid = parentid;
    }

    @Override
    public int compareTo(DingDingDepart o2) {
         if( this.getId() == this.getParentid())  
             return 1;  
         //注意!!返回值必须是一对相反数,否则无效。jdk1.7以后就是这样。  
         //else return 0; 
         //无效  
         else return -1;  
    }
    
    public static void main(String[] args) throws Exception{
        System.out.println("11111");
        DingDingUtil.getAccess_Token();
         
        List<DingDingDepart> list = new ArrayList<DingDingDepart>(); 
        JSONArray departArr = DingDingUtil.getDingDepart();
        for (int i = 0; i < departArr.size(); i++) {
            DingDingDepart depart = new DingDingDepart();
            JSONObject jsonItem = departArr.getJSONObject(i);
            depart.setId(jsonItem.getInteger("id"));
            depart.setName(jsonItem.getString("name"));
            Object pid = jsonItem.get("parentid");
            if(pid!=null){
                depart.setParentid(jsonItem.getInteger("parentid"));
            }else{
                depart.setParentid(0);
            }
            
             
            list.add(depart);
        }
        String a= "";
        for(DingDingDepart de: list){
            a += de.getId()+ ","+de.getParentid() + "||";
        }
        System.out.println(a);
        Collections.sort(list);  
        a= "";
        for(DingDingDepart de: list){
            a += de.getId()+ ","+de.getParentid() + "||";
        }
        System.out.println(a);
    }
}
2017-09-29 15:59:22   Visit  60

使用Nginx做负载均衡时,在默认配置下Nginx默认使用的是轮流转发的模式,这次请求使用第一个服务,下次请求使用第二个服务。如果没有做session共享,就会出现session失效的问题。
比较简单的解决方法是使用 ip做过滤,根据ip来分配使用的服务,这样就保证一个用户会一直请求同一个服务。
配置如下

    upstream tomcat_server{
        ip_hash;
        server 127.0.0.1:8081  weight=1; 
        server 127.0.0.1:8082  weight=1; 
                server 127.0.0.1:8083  weight=1; 
    }

使用Nginx做负载均衡时base href 错误的问题

以下配置会产生base href 错误,造成使用 base href 的页面资源加载异常。

upstream tomcat_server{
     
         server 127.0.0.1:8081;
        
}
server {
        listen       81;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location /  {
            proxy_pass http://tomcat_server;  
        }
}

只需要在 location 中添加以下设置,就会正常

location /  {
            proxy_pass http://tomcat_server; 
            proxy_set_header Host $http_host; 
            proxy_set_header X-Forward-For $remote_addr; 
          }
2017-08-31 14:03:53   Visit  168
select id, name
from  org
start with id = '1' 
connect by prior  id =  pid
2017-08-31 11:31:02   Visit  87

Javascript 获取地址栏参数

(function ($) {
        $.getUrlParam = function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]); return null;
        }
    })(jQuery);
2017-08-30 16:45:40   Visit  100

修改tomcat目录下conf文件夹中的server.xml

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" 
               compression="on"   
               compressionMinSize="50" 
               noCompressionUserAgents="gozilla, traviata"   
               compressableMimeType="text/css,text/html,text/xml,text/javascript,text/css,text/plain,application/javascript"

压缩效果

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/javascript;charset=UTF-8
Transfer-Encoding: chunked
Content-Encoding: gzip
Vary: Accept-Encoding
Date: Wed, 30 Aug 2017 08:44:05 GMT