随笔-71  评论-5  文章-0  trackbacks-0
  2015年8月7日
     摘要: 一个stmt多个rs进行操作.那么从stmt得到的rs1,必须马上操作此rs1后,才能去得到另外的rs2,再对rs2操作.不能互相交替使用,会引起rs已经关闭错误——Operation not allowed after ResultSet closed.错误的代码如下: stmt=conn.createStatement();  rs=stm...  阅读全文
posted @ 2015-10-13 14:58 藤本蔷薇 阅读(187) | 评论 (0)编辑 收藏
在 JDK1.5 引入自动装箱和拆箱的机制后,包装类和基本类型之间的转换就更加轻松便利了。

装箱:把基本类型转换成包装类,使其具有对象的性质,又可分为手动装箱和自动装箱

int i= 10; //定义一个int基本类型值
Integer x = new Integer(i); //手动装箱
Integer y = i; //自动装箱
posted @ 2015-09-22 20:28 藤本蔷薇 阅读(211) | 评论 (0)编辑 收藏

功能:将一个由英文字母组成的字符串转换成指定格式---从右边开始每三个字母用逗号分隔的形式。

请在编辑器中的第 4、10 行将代码填写完整

运行效果: j,aew,kjl,dfx,mop,zdmpublic static void main(String[] args) {
        // Java文件名
String fileName = "HelloWorld.jav"; 
        // 邮箱
String email = "laurenyang@imooc.com";
// 判断.java文件名是否正确:合法的文件名应该以.java结尾
        /*
        参考步骤:
        1、获取文件名中最后一次出现"."号的位置
        2、根据"."号的位置,获取文件的后缀
        3、判断"."号位置及文件后缀名
        */
        //获取文件名中最后一次出现"."号的位置
int index = fileName.lastIndexOf('.');
        
        // 获取文件的后缀
String prefix = fileName.substring(index);
        
// 判断必须包含"."号,且不能出现在首位,同时后缀名为"java"
if (index !=0 && index != -1 &&  prefix.equals("java")) {
System.out.println("Java文件名正确");
} else {
System.out.println("Java文件名无效");
}

        // 判断邮箱格式是否正确:合法的邮箱名中至少要包含"@", 并且"@"是在"."之前
         /*
        参考步骤:
        1、获取文件名中"@"符号的位置
        2、获取邮箱中"."号的位置
        3、判断必须包含"@"符号,且"@"必须在"."之前
        */
   // 获取邮箱中"@"符号的位置
int index2 = email.indexOf("@");
        
        // 获取邮箱中"."号的位置
int index3 = email.indexOf('.');
        
// 判断必须包含"@"符号,且"@"必须在"."之前
if (index2 != -1 && index3 > index2) {
System.out.println("邮箱格式正确");
} else {
System.out.println("邮箱格式无效");
}
}






字节是计算机存储信息的基本单位,1 个字节等于 8 位, gbk 编码中 1 个汉字字符存储需要 2 个字节1 个英文字符存储需要 1 个字节。所以我们看到上面的程序运行结果中,每个汉字对应两个字节值,如“学”对应 “-47 -89” ,而英文字母 “J” 对应 “74” 。同时,我们还发现汉字对应的字节值为负数,原因在于每个字节是 8 位,最大值不能超过 127,而汉字转换为字节后超过 127,如果超过就会溢出,以负数的形式显示。






     public static void main(String[] args) {
// 定义一个字符串
String s = "aljlkdsflkjsadjfklhasdkjlflkajdflwoiudsafhaasdasd";
        
        // 出现次数
int num = 0;
         // 循环遍历每个字符,判断是否是字符 a ,如果是,累加次数
for ( int i=0;i<s.length()-1;i++)
{
            // 获取每个字符,判断是否是字符a
if (  'a'==s.charAt(i)      ) {
                // 累加统计次数
num++; 
}
}
System.out.println("字符a出现的次数:" + num);
}




功能:将一个由英文字母组成的字符串转换成指定格式---从右边开始每三个字母用逗号分隔的形式。

请在编辑器中的第 4、10 行将代码填写完整

运行效果: j,aew,kjl,dfx,mop,zdm


    public static void main(String[] args) {
// 创建一个空的StringBuilder对象
        StringBuilder str = new StringBuilder();
// 追加字符串
str.append("jaewkjldfxmopzdm");
        // 从后往前每隔三位插入逗号
for(int i = str.length()-3; i>0 ; i=i-3){
     
           str.insert(i,",");
}
    
        // 将StringBuilder对象转换为String对象并输出
System.out.print(str.toString());
}

 结果: j,aew,kjl,dfx,mop,zdm
posted @ 2015-09-22 16:12 藤本蔷薇 阅读(336) | 评论 (0)编辑 收藏
String s1 = "imooc";
String s2 = "imooc";
        
        //定义字符串s3,保存“I love”和s1拼接后的内容
String s3 = "I love" + s1; 
        // 比较字符串s1和s2
// imooc为常量字符串,多次出现时会被编译器优化,只创建一个对象
System.out.println("s1和s2内存地址相同吗?" + (s1 == s2));
        
        //比较字符串s1和s3
System.out.println("s1和s3内存地址相同吗?" +  (s1==s3));
String s4 = "I love " + s1;
         //比较字符串s4和s3
// s1是变量,s4在运行时才知道具体值,所以s3和s4是不同的对象
System.out.println("s3和s4内存地址相同吗?" + (s4 == s3));
posted @ 2015-09-22 15:26 藤本蔷薇 阅读(245) | 评论 (0)编辑 收藏
//外部类HelloWorld
public class HelloWorld {
    
    // 内部类Inner,类Inner在类HelloWorld的内部
    public class Inner {
        
// 内部类的方法
public void show() {
System.out.println("welcome to imooc!");
}
}
    
public static void main(String[] args) {
        
        // 创建外部类对象
HelloWorld hello = new HelloWorld();
        // 创建内部类对象
Inner i = hello.new Inner();
        // 调用内部类对象的方法
i.show();
}
}
posted @ 2015-09-09 15:47 藤本蔷薇 阅读(299) | 评论 (0)编辑 收藏














posted @ 2015-09-09 14:41 藤本蔷薇 阅读(310) | 评论 (0)编辑 收藏
不清楚路径的查找 : find / -name mysql


 MYSQL常用经典命令(没有试过)
1.停止mysql
kill -9 `ps -ef | grep mysqld_safe| grep -v grep| awk '{print $2}'`
kill -9 `ps -ef | grep 'mysqld' | grep -v grep| awk '{print $2}'`

2.启动mysql
cd /usr/local/mysql-5.4.1-beta-linux-x86_64-glibc23
/bin/sh bin/mysqld_safe --user=mysql & 


find /home/lijiajia/ -amin -10        #查找在系统中最后10分钟访问的文件
find /home/lijiajia/ -atime -2        #查找在系统中最后48小时访问的文件
find /home/lijiajia/ -empty           #查找在系统中为空的文件或者文件夹
find /home/lijiajia/ -mmin -5         # 查找在系统中最后5 分钟里修改过的文件
find /home/lijiajia/ -mtime -1        #查找在系统中最后24 小时里修改过的文件
find /home/lijiajia/ -nouser          #查找在系统中属于作废用户的文件(不明白是什么意思)
find /home/lijiajia/ -amin 10         #查找在系统中最后10分钟访问的文件
find /home/ftp/pub -user lijiajia     #查找在系统中属于lijiajia这个用户的文件
posted @ 2015-09-02 10:26 藤本蔷薇 阅读(200) | 评论 (0)编辑 收藏
  public static Map ConvertObjToMap(Object obj){
              Map<String,Object> reMap = new HashMap<String,Object>();
              if (obj == null
               return null;
              Field[] fields = obj.getClass().getDeclaredFields();
              try {
               for(int i=0;i<fields.length;i++){
                try {
                 Field f = obj.getClass().getDeclaredField(fields[i].getName());
                 f.setAccessible(true);
                       Object o = f.get(obj);
                       if(o == null){
                           o = "";
                       }else{
                           o = String.valueOf(o);
                       }
                       reMap.put(fields[i].getName(), String.valueOf(o));
                } catch (NoSuchFieldException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
                } catch (IllegalArgumentException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
                } catch (IllegalAccessException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
                }
               }
              } catch (SecurityException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
              } 
              return reMap;
             }
posted @ 2015-08-31 19:52 藤本蔷薇 阅读(997) | 评论 (0)编辑 收藏

import java.io.IOException;
import java.util.Date;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.alibaba.fastjson.JSONObject;
import com.huoniu.openapi.constant.Constant.MESSAGE;
import com.huoniu.openapi.constant.InvokeContext;
import com.huoniu.openapi.model.RetCode;
import com.huoniu.openapi.model.RetMsg;
import com.huoniu.openapi.model.SmsCode;
import com.huoniu.openapi.service.SmsCodeService;
import com.huoniu.openapi.utils.AESUtil;
import com.huoniu.openapi.utils.SmsUtil;
import com.huoniu.openapi.web.interceptor.InvokeContextInitInterceptor;
import com.puff.framework.annotation.Before;
import com.puff.framework.annotation.Controller;
import com.puff.framework.annotation.Inject;
import com.puff.framework.annotation.InterceptorChain;
import com.puff.framework.utils.JsonUtil;
import com.puff.framework.utils.StringUtil;
import com.puff.web.view.TextView;
import com.puff.web.view.View;
import com.puff.web.view.ViewFactory;

@Controller("/rest/sms")
public class HuyiSmsController {    

    private static String content = "您的验证码是:%s。请不要把验证码泄露给其他人。";
    public View send(){
        
        String invokeData = InvokeContext.getInvokeData();
        if (StringUtil.blank(invokeData)) {
            return json(RetMsg.error(RetCode.OTHER_ERROR, "发送短信失败!"));
        }
        
        JSONObject jsonObject = JSONObject.parseObject(invokeData);
        String  mobile = jsonObject.getString("customer_no");
        if (StringUtil.blank(mobile)) {
            return json(RetMsg.error(RetCode.NULL_PARAM, "手机号码不能为空"));
        }
            
            HttpClient client = new HttpClient(); 
            PostMethod method = new PostMethod(MESSAGE.NEW_MESSAGEURL);  //接口地址
                
            client.getParams().setContentCharset("UTF-8");
            method.setRequestHeader("ContentType","application/x-www-form-urlencoded;charset=UTF-8");

            int mobile_code = (int)((Math.random()*9+1)*100000);        
                                               System.out.println("mobile_code : "+mobile_code);
            NameValuePair[] data = {//提交短信
                    new NameValuePair("account", MESSAGE.NEW_ACCOUNT), 
                    new NameValuePair("password", SmsUtil.MD5Encode(MESSAGE.NEW_PASSWORD)),
                    new NameValuePair("mobile", mobile), 
                    new NameValuePair("content", String.format(content, mobile_code)),
            };
            
            method.setRequestBody(data);        

            try {
                client.executeMethod(method);    
                String SubmitResult =method.getResponseBodyAsString();
                Document doc = DocumentHelper.parseText(SubmitResult); 
                Element root = doc.getRootElement();
                String code = root.elementText("code");    
                String msg = root.elementText("msg");    
                String smsid = root.elementText("smsid");    
                            
                if(code == "2"){  //发送成功,写库
                    
                }
                
            } catch (HttpException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (DocumentException e) {
                e.printStackTrace();
            }    
            
        
            return json(RetMsg.success("发送成功!!!"));
        
    }
    
    
    
    public View json(RetMsg msg) {
        String data = JsonUtil.toJson(msg);
        if (InvokeContext.isEncrypt()) {
            data = AESUtil.encrypt(data);
        }
        return ViewFactory.text(data, TextView.ContentType.JSON);
    }

}
posted @ 2015-08-31 10:02 藤本蔷薇 阅读(287) | 评论 (0)编辑 收藏
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

import com.alibaba.fastjson.JSONObject;
import com.huoniu.openapi.constant.Constant.TONGLIAN;


public class TLInterfaceService {
    
    private static final String USERNAME = "";
    private static final String PASSWORD = "";
    private static final String TENANT = "";
    private static final String GRANT_TYPE_GET = "password";    
    private static final String GRANT_TYPE_REFRESH = "refresh_token";    
    
    private static String TOKEN = null;
    private static String REFRESH_TOKEN = null;
    private static long EXPIRES_IN ;
    private static long START_DATE;

    
    public  String getToken() {
        if(TOKEN==null){
                TOKEN  = login();
        }else{
            Date date = new Date();
            if(START_DATE-date.getTime()<EXPIRES_IN-30){
                TOKEN  = refresh();
            }
            
        }
        
        return TOKEN;
    }
    
    
    public  void setToken(String token) {
        TOKEN = token;
    }


    /**
     * 登陆,获取token
     * 
@return 
     
*/
            
        public static String login(){

                HttpClient httpClient = new HttpClient();
                String URL = String.format(TONGLIAN.PREV_PATH, "");  //接口地址
                try {
                    PostMethod postMethod = new PostMethod(URL);
                    postMethod.addRequestHeader("Content-Type","application/x-www-form-urlencoded");
                    NameValuePair[] data = { 
                            new NameValuePair("username", USERNAME),
                            new NameValuePair("password", PASSWORD),
                            new NameValuePair("tenant",  TENANT),
                            new NameValuePair("grant_type", GRANT_TYPE_GET)
                             };
                    postMethod.setRequestBody(data);
                    int statusCode = httpClient.executeMethod(postMethod);
                    if(200 == statusCode){
                        String body  = postMethod.getResponseBodyAsString();
                        JSONObject json=JSONObject.parseObject(body);
                        TOKEN = json.getString("access_token");
                        REFRESH_TOKEN = json.getString("refresh_token");
                        EXPIRES_IN = Long.parseLong(json.getString("expires_in"));
                        START_DATE =  (new Date()).getTime();
                    }
                } catch (Exception e) {
                    
                }
                return TOKEN;
         }
        
        /**
         * refresh_token
         * 
@return 
         
*/
                        
        public static String refresh(){
                
            HttpClient httpClient = new HttpClient();
                String URL = String.format(TONGLIAN.PREV_PATH, ""); //接口地址
                try {
                    PostMethod postMethod = new PostMethod(URL);
                    postMethod.addRequestHeader("Content-Type","application/x-www-form-urlencoded");
                    NameValuePair[] data = { 
                            new NameValuePair("refresh_token", REFRESH_TOKEN),
                            new NameValuePair("grant_type", GRANT_TYPE_REFRESH)
                     };
                    postMethod.setRequestBody(data);
                    int statusCode = httpClient.executeMethod(postMethod);
                    
                    if(200 == statusCode){
                        String body  = postMethod.getResponseBodyAsString();
                        JSONObject json=JSONObject.parseObject(body);
                        TOKEN = json.getString("access_token");
                        REFRESH_TOKEN = json.getString("refresh_token");
                        EXPIRES_IN = Long.parseLong(json.getString("expires_in"));
                        START_DATE =  (new Date()).getTime();
                    }
                } catch (Exception e) {
                    
                }
                return TOKEN;
         }

}
posted @ 2015-08-31 09:54 藤本蔷薇 阅读(269) | 评论 (0)编辑 收藏

/Files/kokosang/html5拖拽上传.zip

  前几天想做个给安卓app升级做个上传页面,然后从网上down了个页面下面(主要是嫌弃自己页面整的太丑,见不了人),然后就一直在整后台取值的办法
  各种百度,值取出来了,但是,悲催的是总是乱码,崩溃了,大神看了后,鄙视一番,给我整了下,简直就是重写了

  贴出来,先放张页面效果
  


  赏心悦目的后台来咯

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.tomcat.util.http.fileupload.FileItem;
import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory;
import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload;

import com.puff.framework.annotation.Controller;
import com.puff.web.mvc.PuffContext;
import com.puff.web.view.View;

@Controller("/upload/android")
public class AndroidVersionUploadController {

    private static final Logger logger = Logger.getLogger(UserImageController.class);
    
    private static final String FILE_PATH = "C:/Users/Administrator/Desktop";
    
    private static final String FILE_APK_NAME = "/nn.apk";
    private static final String FILE_VER_NAME = "/ver.txt";
    
    /**
     * 版本上传
     * 
@return
     * 
@throws Exception 
     
*/
    public View update() throws Exception {
        DiskFileItemFactory factory = new DiskFileItemFactory(); 
        ServletFileUpload upload = new ServletFileUpload(factory); 
        List<FileItem> items = upload.parseRequest( PuffContext.getRequest()); 
        
        String ver = null;
        String info = null;
        String isFoucs = null;
        for(Object object : items) { 
            FileItem fileItem = (FileItem)object; 
            if(fileItem.isFormField()) { 
                
                String name = fileItem.getFieldName();
                String value = fileItem.getString("utf-8");
                
                if("ver".equals(name)){
                    ver = value;
                }else if("content".equals(name)){
                    info = value;
                }else if("radio".equals(name)){
                    isFoucs = value;
                }
            } else {
                saveFileInfo(fileItem);
            }
        } 
        
        saveContentInfo(ver, info, isFoucs);
        
        return null;
    
    }

    private void saveFileInfo(FileItem fileItem) {
        
        InputStream is = null;
        OutputStream os = null;
        try {
            File file = new File(FILE_PATH);
            if(file.exists()) {
                file.mkdirs();
            }
            
            is = fileItem.getInputStream();
            os = new FileOutputStream(FILE_PATH + FILE_APK_NAME);
            
            int len = 0;
            byte[] buffer = new byte[8 * 1024];
            while ((len = is.read(buffer, 0, 8 * 1024)) != -1) {
                os.write(buffer, 0, len);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            closeOutputStream(os);
            closeInputStream(is);
        }
    }
    
    public void saveContentInfo(String ver, String info, String isFoucs) {
        BufferedWriter br = null;
        try {
            File file = new File(FILE_PATH);
            if(file.exists()) {
                file.mkdirs();
            }
            
            br = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(FILE_PATH + FILE_VER_NAME), "utf-8"));
            br.write("ver:" + ver + "\r\n");   //版本号
            br.write("update:" + isFoucs+ "\r\n");   //是否强制更新
            br.write("content:" + info );    //版本升级内容
            br.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if(br != null) {
                    br.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                br = null;
            }
        }
    }


    private void closeOutputStream(OutputStream os) {
        if(os != null) {
            try {
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                os = null;
            }
        }
    }
    
    private void closeInputStream(InputStream is) {
        if(is != null) {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                is = null;
            }
        }
    }
}
posted @ 2015-08-24 10:35 藤本蔷薇 阅读(254) | 评论 (0)编辑 收藏
public static void main(String[] args) {

        String xml = "<?xml version=\"1.0\" encoding=\"gb2312\"?><p><seqid></seqid><code></code><msg>成功</msg>" +
                          "<node><ename>huoniu</ename><cname>火牛</cname><prefix>108</prefix><begin>20150603</begin><end>20160630</end><borr>1000000</borr><margin>100000</margin><usdborr>1000000</usdborr><usdmargin>100000</usdmargin><mainp>0.60</mainp><midp>0.60</midp><growp>0.60</growp><mainpt>0.60</mainpt><midpt>0.60</midpt><growpt>0.30</growpt><shcomm>0.000300</shcomm><szcomm>0.000300</szcomm><warn>1.000</warn><close>1.000</close><interest>200</interest><commf>13</commf><layout>p-huo01:1100000:574810</layout><unmoney>0</unmoney><tstatus>0</tstatus><cstatus>0</cstatus></node>" +
                          " <node><ename>nn</ename><cname>牛牛</cname><prefix>102</prefix><begin>20150615</begin><end>20151015</end><borr>10000000</borr><margin>8000000</margin><usdborr>10000000</usdborr><usdmargin>8000000</usdmargin><mainp>0.60</mainp><midp>0.60</midp><growp>0.30</growp><mainpt>0.60</mainpt><midpt>0.60</midpt><growpt>0.30</growpt><shcomm>0.003000</shcomm><szcomm>0.003000</szcomm><warn>0.800</warn><close>0.800</close><interest>0</interest><commf>0</commf><layout></layout><unmoney>18000000</unmoney><tstatus>0</tstatus><cstatus>0</cstatus></node>" +
                         "<node><ename>ag-huo</ename><cname>兜底代理商</cname><prefix>huo</prefix><begin>20150602</begin><end>20160630</end><borr>0</borr><margin>0</margin><usdborr>0</usdborr><usdmargin>0</usdmargin><mainp>0.60</mainp><midp>0.60</midp><growp>0.30</growp><mainpt>0.60</mainpt><midpt>0.60</midpt><growpt>0.30</growpt><shcomm>0.000300</shcomm><szcomm>0.000300</szcomm><warn>0.010</warn><close>0.010</close><interest>0</interest><commf>0</commf><layout></layout><unmoney>0</unmoney><tstatus>0</tstatus><cstatus>0</cstatus></node></p>";

        List<Map> nodeList = new ArrayList<Map>();
        Map<String, Object> sendMap = new HashMap<String, Object>();
        try {
            
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.parse(new InputSource(new StringReader(xml)));
            Element root = doc.getDocumentElement();// 根节点

            Node node = root.getFirstChild();
            while(node != null) {
                String nodeName = node.getNodeName().trim();
                String nodeValue = node.getTextContent().trim();
                
                if("node".equals(nodeName) && node.hasChildNodes()) {
                    
                    Map<String, Object> nodeMap = new HashMap<String, Object>();
                    
                    Node childNode = node.getFirstChild();
                    while(childNode != null) {
                        nodeMap.put(childNode.getNodeName(), childNode.getTextContent());
                        childNode = childNode.getNextSibling();
                    }
                    
                    nodeList.add(nodeMap);
                } else {
                    sendMap.put(nodeName, nodeValue);
                }
                
                node = node.getNextSibling();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        sendMap.put("node", nodeList);
        
        System.out.println(sendMap);
    }



打印结果 :
{node=[{warn=1.000, cstatus=0, tstatus=0, borr=1000000, growpt=0.30, unmoney=0, midpt=0.60, usdmargin=100000, commf=13, close=1.000, begin=20150603, shcomm=0.000300, usdborr=1000000, growp=0.60, interest=200, layout=p-huo01:1100000:574810, prefix=108, ename=huoniu, midp=0.60, mainpt=0.60, margin=100000, szcomm=0.000300, cname=火牛, end=20160630, mainp=0.60}, 
            {warn=0.800, cstatus=0, tstatus=0, borr=10000000, growpt=0.30, unmoney=18000000, midpt=0.60, usdmargin=8000000, commf=0, close=0.800, begin=20150615, shcomm=0.003000, usdborr=10000000, growp=0.30, interest=0, layout=, ename=nn, midp=0.60, mainpt=0.60, margin=8000000, szcomm=0.003000, end=20151015, mainp=0.60},
            {warn=0.010, cstatus=0, tstatus=0, borr=0, growpt=0.30, unmoney=0, midpt=0.60, usdmargin=0, commf=0, close=0.010, begin=20150602, shcomm=0.000300, usdborr=0, growp=0.30, interest=0, layout=, prefix=huo, ename=ag-huo, midp=0.60, mainpt=0.60, margin=0, szcomm=0.000300, end=20160630, mainp=0.60}], seqid=, code=, msg=成功}
posted @ 2015-08-09 10:15 藤本蔷薇 阅读(256) | 评论 (0)编辑 收藏
      public static void main(String[] args) throws Exception {
            Map<String, Object> sendMap = new HashMap<String, Object>();
            String data = "<?xml version=\"1.0\" encoding=\"gb2312\"?><p><seqid></seqid><client>0BF3F2D9A01797BBF05D6BC89877DC91</client><ename>108-wc</ename><code>0</code><msg>成功</msg><totalm>12447.97</totalm><cash>5669.13</cash><stockm>6778.84</stockm><num>2</num><stock><node><market>0</market><symbol>600104</symbol><direct>1</direct><type>0</type><avgprice>21.010</avgprice><holdnum>299</holdnum></node><node><market>0</market><symbol>601818</symbol><direct>1</direct><type>0</type><avgprice>4.993</avgprice><holdnum>4</holdnum></node></stock></p>";

            List<Map> nodeList = new ArrayList<Map>();
            try {
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder db = dbf.newDocumentBuilder();
                Document doc = db.parse(new InputSource(new StringReader(data)));
                Element root = doc.getDocumentElement();// 根节点
                Node node = root.getFirstChild();
                while(node != null) {
                    String nodeName = node.getNodeName().trim();
                    String nodeValue = node.getTextContent().trim();
                    if("stock".equals(nodeName) && node.hasChildNodes()) {
                        Node  nodeOne =  node.getFirstChild();
                        while(nodeOne != null) {
                         String nodeOneName = nodeOne.getNodeName().trim();
                         if("node".equals(nodeOneName) && nodeOne.hasChildNodes()){
                             Map<String, Object> nodeMap = new HashMap<String, Object>();
                              Node threeNode = nodeOne.getFirstChild();
                                while(threeNode != null) {
                                    nodeMap.put(threeNode.getNodeName(), threeNode.getTextContent());
                                    threeNode = threeNode.getNextSibling();
                                }
                                nodeList.add(nodeMap);
                              }
                           nodeOne = nodeOne.getNextSibling();
                           }
                        }else{
                            sendMap.put(nodeName, nodeValue);
                        }
                    node = node.getNextSibling();
                    }                    
                sendMap.put("node", nodeList);
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println(sendMap);
      }  


打印结果:{node=[{direct=1, market=0, symbol=600104, avgprice=21.010, holdnum=299, type=0},
             {direct=1, market=0, symbol=601818, avgprice=4.993, holdnum=4, type=0}],
              num=2, seqid=, client=0BF3F2D9A01797BBF05D6BC89877DC91, stockm=6778.84, cash=5669.13, ename=108-wc, code=0, totalm=12447.97, msg=成功}
posted @ 2015-08-09 10:09 藤本蔷薇 阅读(466) | 评论 (0)编辑 收藏
/Files/kokosang/DoubleUtil.txt



package frameWork.util;
import java.math.BigDecimal;
import java.text.DecimalFormat;
/**   
 * 由于Java的简单类型不能够精确的对浮点数进行运算,这个工具类提供精   
 * 确的浮点数运算,包括加减乘除和四舍五入。   
 */    
public class DoubleUtil {
//这个类不能实例化    
private DoubleUtil(){    
}  
//默认除法运算精度    
private static final int DEF_DIV_SCALE = 10;  
//默认的保留位数
private static DecimalFormat df=new DecimalFormat("0.00");  
/**
* 按照格式保留几位
* @param money  double数
* @param format 格式
* @return
*/
public static double  format(double money,String format){
if(format != null && format != ""){
df=new DecimalFormat(format); 
}
double moneyformat=new Double(df.format(money).toString());  
return moneyformat;
}
/**   
* 提供精确的加法运算。   
* @param v1 被加数   
* @param v2 加数   
* @return 两个参数的和   
*/    
public static double add(double v1,double v2){    
BigDecimal b1 = new BigDecimal(Double.toString(v1));    
BigDecimal b2 = new BigDecimal(Double.toString(v2));    
return b1.add(b2).doubleValue();    
}    
/**   
* 提供精确的减法运算。   
* @param v1 被减数   
* @param v2 减数   
* @return 两个参数的差   
*/    
public static double sub(double v1,double v2){    
BigDecimal b1 = new BigDecimal(Double.toString(v1));    
BigDecimal b2 = new BigDecimal(Double.toString(v2));    
return b1.subtract(b2).doubleValue();    
}    
/**   
* 提供精确的乘法运算。   
* @param v1 被乘数   
* @param v2 乘数   
* @return 两个参数的积   
*/    
public static double mul(double v1,double v2){    
BigDecimal b1 = new BigDecimal(Double.toString(v1));    
BigDecimal b2 = new BigDecimal(Double.toString(v2));    
return b1.multiply(b2).doubleValue();    
}    
/**   
* 提供(相对)精确的除法运算,当发生除不尽的情况时,精确到   
* 小数点以后10位,以后的数字四舍五入。   
* @param v1 被除数   
* @param v2 除数   
* @return 两个参数的商   
*/    
public static double div(double v1,double v2){    
return div(v1,v2,DEF_DIV_SCALE);    
}    
/**   
* 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指   
* 定精度,以后的数字四舍五入。   
* @param v1 被除数   
* @param v2 除数   
* @param scale 表示表示需要精确到小数点以后几位。   
* @return 两个参数的商   
*/    
public static double div(double v1,double v2,int scale){    
if(scale<0){    
throw new IllegalArgumentException("The scale must be a positive integer or zero");    
}    
BigDecimal b1 = new BigDecimal(Double.toString(v1));    
BigDecimal b2 = new BigDecimal(Double.toString(v2));    
return b1.divide(b2,scale,BigDecimal.ROUND_HALF_UP).doubleValue();    
}    
/**   
* 提供精确的小数位四舍五入处理。   
* @param v 需要四舍五入的数字   
* @param scale 小数点后保留几位   
* @return 四舍五入后的结果   
*/    
public static double round(double v,int scale){    
if(scale<0){    
throw new IllegalArgumentException("The scale must be a positive integer or zero");    
}    
BigDecimal b = new BigDecimal(Double.toString(v));    
BigDecimal one = new BigDecimal("1");    
return b.divide(one,scale,BigDecimal.ROUND_HALF_UP).doubleValue();    
}    
/**   
* 提供精确的类型转换(Float)   
* @param v 需要被转换的数字   
* @return 返回转换结果   
*/    
public static float convertsToFloat(double v){    
BigDecimal b = new BigDecimal(v);    
return b.floatValue();    
}    
/**   
* 提供精确的类型转换(Int)不进行四舍五入   
* @param v 需要被转换的数字   
* @return 返回转换结果   
*/    
public static int convertsToInt(double v){    
BigDecimal b = new BigDecimal(v);    
return b.intValue();    
}    
/**   
* 提供精确的类型转换(Long)   
* @param v 需要被转换的数字   
* @return 返回转换结果   
*/    
public static long convertsToLong(double v){    
BigDecimal b = new BigDecimal(v);    
return b.longValue();    
}    
/**   
* 返回两个数中大的一个值   
* @param v1 需要被对比的第一个数   
* @param v2 需要被对比的第二个数   
* @return 返回两个数中大的一个值   
*/    
public static double returnMax(double v1,double v2){    
BigDecimal b1 = new BigDecimal(v1);    
BigDecimal b2 = new BigDecimal(v2);    
return b1.max(b2).doubleValue();    
}    
/**   
* 返回两个数中小的一个值   
* @param v1 需要被对比的第一个数   
* @param v2 需要被对比的第二个数   
* @return 返回两个数中小的一个值   
*/    
public static double returnMin(double v1,double v2){    
BigDecimal b1 = new BigDecimal(v1);    
BigDecimal b2 = new BigDecimal(v2);    
return b1.min(b2).doubleValue();    
}    
/**   
* 精确对比两个数字   
* @param v1 需要被对比的第一个数   
* @param v2 需要被对比的第二个数   
* @return 如果两个数一样则返回0,如果第一个数比第二个数大则返回1,反之返回-1   
*/    
public static int compareTo(double v1,double v2){    
BigDecimal b1 = new BigDecimal(v1);    
BigDecimal b2 = new BigDecimal(v2);    
return b1.compareTo(b2);    
}
/**
* 格式化double
* @param arg0
* @param num
* @return
*/
public static String doubleFormat(double arg0,Integer num){
DecimalFormat df = new DecimalFormat("####.00"); 
/*DecimalFormat df2 = new DecimalFormat("##.00%");  
DecimalFormat df3 = new DecimalFormat("###,##0.00");*/
if(num !=null){
if(num == 1){
df = new DecimalFormat("####.0"); 
}else if(num == 2){
df = new DecimalFormat("####.00"); 
}else if(num == 3){
df = new DecimalFormat("####.000"); 
}else if(num == 4){
df = new DecimalFormat("####.0000"); 
}
}else{
df = new DecimalFormat("####"); 
}
if(df.format(arg0).contains(".")){
if(df.format(arg0).substring(0, df.format(arg0).indexOf(".")).length()<=0){
df = new DecimalFormat("0.00");
if(num !=null){
if(num == 1){
df = new DecimalFormat("0.0"); 
}else if(num == 2){
df = new DecimalFormat("0.00"); 
}else if(num == 3){
df = new DecimalFormat("0.000"); 
}else if(num == 4){
df = new DecimalFormat("0.0000"); 
}
}else{
df = new DecimalFormat("0"); 
}
}
}
return df.format(arg0);
}
/**
* 百分比格式化
* @param arg0
* @param num
* @return
*/
public static String percentageFormat(double arg0,Integer num){
DecimalFormat df = new DecimalFormat("##.00%");
if(num !=null){
if(num == 1){
df = new DecimalFormat("####.0%"); 
}else if(num == 2){
df = new DecimalFormat("####.00%"); 
}else if(num == 3){
df = new DecimalFormat("####.000%"); 
}else if(num == 4){
df = new DecimalFormat("####.0000%"); 
}
}else{
df = new DecimalFormat("####%"); 
}
if(df.format(arg0).contains(".")){
if(df.format(arg0).substring(0, df.format(arg0).indexOf(".")).length()<=0){
df = new DecimalFormat("0.00%");
if(num !=null){
if(num == 1){
df = new DecimalFormat("0.0%"); 
}else if(num == 2){
df = new DecimalFormat("0.00%"); 
}else if(num == 3){
df = new DecimalFormat("0.000%"); 
}else if(num == 4){
df = new DecimalFormat("0.0000%"); 
}
}else{
df = new DecimalFormat("0%"); 
}
}
}
return df.format(arg0);
}
/**
* double每三位短号分割
* @param arg0
* @param num
* @return
*/
public static String splitNumberFormat(double arg0,Integer num){
DecimalFormat df = new DecimalFormat("###,##0.00");
if(num !=null){
if(num == 1){
df = new DecimalFormat("###,##0.0"); 
}else if(num == 2){
df = new DecimalFormat("###,##0.00"); 
}else if(num == 3){
df = new DecimalFormat("###,##0.000"); 
}else if(num == 4){
df = new DecimalFormat("###,##0.0000"); 
}
}else{
df = new DecimalFormat("###,###"); 
}
return df.format(arg0);
}
}
posted @ 2015-08-07 13:47 藤本蔷薇 阅读(562) | 评论 (0)编辑 收藏
假如  redis  在/usr/local/bin

配置文件在/usr/local/redis-2.8.21 

 root@iZ239bujfzrZ:    /usr/local/bin# ./redis-server redis.conf nohup 
posted @ 2015-08-07 10:36 藤本蔷薇 阅读(208) | 评论 (0)编辑 收藏