﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-休息食客-随笔分类-java</title><link>http://www.blogjava.net/resteater/category/54708.html</link><description>随心而动</description><language>zh-cn</language><lastBuildDate>Sat, 12 Sep 2015 05:09:48 GMT</lastBuildDate><pubDate>Sat, 12 Sep 2015 05:09:48 GMT</pubDate><ttl>60</ttl><item><title>微信现金红包开发2（JAVA）</title><link>http://www.blogjava.net/resteater/archive/2015/09/11/427271.html</link><dc:creator>休息食客</dc:creator><author>休息食客</author><pubDate>Fri, 11 Sep 2015 07:46:00 GMT</pubDate><guid>http://www.blogjava.net/resteater/archive/2015/09/11/427271.html</guid><wfw:comment>http://www.blogjava.net/resteater/comments/427271.html</wfw:comment><comments>http://www.blogjava.net/resteater/archive/2015/09/11/427271.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/resteater/comments/commentRss/427271.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/resteater/services/trackbacks/427271.html</trackback:ping><description><![CDATA[<span style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">第一节讲了怎么准备所有的参数，这里讲怎么将这些参数组成xml（即要通过HTTPS发送的数据）</span><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">大家可以先在网上了解一下java bean转xml的相关知识</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">1、我建了里一个请求参数类</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">public class WechatCashHongbaoSendReq {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;private String nonce_str; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //随机字符串</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;private String sign; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//签名</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;private String mch_billno; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//商户订单号</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;private String mch_id; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//商户号</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;private String wxappid; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //公众账号appid</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;private String send_name; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //商户名称</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;private String re_openid; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //用户openid</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;private int total_amount; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//付款金额</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;private int total_num; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //红包发放总人数</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;private String wishing; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //红包祝福语</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;private String client_ip; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Ip地址</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;private String act_name; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//活动名称</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;private String remark; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//备注</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public String getNonce_str() {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; return nonce_str;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public void setNonce_str(String nonce_str) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; this.nonce_str = nonce_str;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public String getSign() {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; return sign;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public void setSign(String sign) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; this.sign = sign;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public String getMch_billno() {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; return mch_billno;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public void setMch_billno(String mch_billno) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; this.mch_billno = mch_billno;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public String getMch_id() {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; return mch_id;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public void setMch_id(String mch_id) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; this.mch_id = mch_id;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public String getWxappid() {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; return wxappid;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public void setWxappid(String wxappid) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; this.wxappid = wxappid;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public String getSend_name() {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; return send_name;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public void setSend_name(String send_name) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; this.send_name = send_name;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public String getRe_openid() {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; return re_openid;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public void setRe_openid(String re_openid) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; this.re_openid = re_openid;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public int getTotal_amount() {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; return total_amount;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public void setTotal_amount(int total_amount) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; this.total_amount = total_amount;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public int getTotal_num() {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; return total_num;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public void setTotal_num(int total_num) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; this.total_num = total_num;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public String getWishing() {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; return wishing;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public void setWishing(String wishing) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; this.wishing = wishing;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public String getClient_ip() {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; return client_ip;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public void setClient_ip(String client_ip) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; this.client_ip = client_ip;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public String getAct_name() {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; return act_name;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public void setAct_name(String act_name) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; this.act_name = act_name;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public String getRemark() {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; return remark;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;public void setRemark(String remark) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; this.remark = remark;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="background-color: inherit; line-height: 1.5;"><br style="background-color: inherit;" /></span></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="background-color: inherit; line-height: 1.5;">2、然后把13个参数都set进去</span></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">WechatCashHongbaoSendReq sendReq = new WechatCashHongbaoSendReq();</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; sendReq.setNonce_str(nonce_str);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; sendReq.setSign(sign);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; sendReq.setMch_billno(mch_billno);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; sendReq.setMch_id(mch_id);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; sendReq.setWxappid(wxappid);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; sendReq.setSend_name(send_name);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; sendReq.setRe_openid(re_openid);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; sendReq.setTotal_amount(total_amount);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; sendReq.setTotal_num(total_num);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; sendReq.setWishing(wishing);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; sendReq.setClient_ip(client_ip);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; sendReq.setAct_name(act_name);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; sendReq.setRemark(remark);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">3、将请求类转为xml</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">String data = Util.bean2XML(req).replaceAll("__", "_"); &nbsp; &nbsp;//为什么要加一个replaceAll("__", "_"),如果不加，会有什么情况，大家可以试试</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">写一个Util类，代码如下：</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">import com.thoughtworks.xstream.XStream;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">import com.thoughtworks.xstream.core.util.QuickWriter;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">import com.thoughtworks.xstream.io.HierarchicalStreamWriter;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">import com.thoughtworks.xstream.io.xml.XppDriver;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">import java.io.*;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">import java.lang.reflect.Field;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">import java.util.Map;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">/**</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;* User: rizenguo</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;* Date: 2014/10/23</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;* Time: 14:59</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;*/</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">public class Util {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; //打log用</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; /**</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;* 通过反射的方式遍历对象的属性和属性值，方便调试</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;*</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;* @param o 要遍历的对象</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;* @throws Exception</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;*/</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; public static void reflect(Object o) throws Exception {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; Class cls = o.getClass();</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; Field[] fields = cls.getDeclaredFields();</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i &lt; fields.length; i++) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Field f = fields[i];</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f.setAccessible(true);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Util.log(f.getName() + " -&gt; " + f.get(o));</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; public static byte[] readInput(InputStream in) throws IOException {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; ByteArrayOutputStream out = new ByteArrayOutputStream();</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; int len = 0;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; byte[] buffer = new byte[1024];</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; while ((len = in.read(buffer)) &gt; 0) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; out.write(buffer, 0, len);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; out.close();</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; in.close();</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; return out.toByteArray();</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; public static String inputStreamToString(InputStream is) throws IOException {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; ByteArrayOutputStream baos = new ByteArrayOutputStream();</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; int i;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; while ((i = is.read()) != -1) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; baos.write(i);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; return baos.toString();</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; public static InputStream getStringStream(String sInputString) throws UnsupportedEncodingException {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; ByteArrayInputStream tInputStringStream = null;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; if (sInputString != null &amp;&amp; !sInputString.trim().equals("")) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tInputStringStream = new ByteArrayInputStream(sInputString.getBytes("UTF-8"));</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; return tInputStringStream;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; public static Object getObjectFromXML(String xml, Class tClass) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; //将从API返回的XML数据映射到Java对象</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;xstream.alias("xml", tClass);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; return xstream.fromXML(xml);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; public static String getStringFromMap(Map&lt;String, Object&gt; map, String key, String defaultValue) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; if (key == "" || key == null) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return defaultValue;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; String result = (String) map.get(key);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; if (result == null) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return defaultValue;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; } else {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return result;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; public static int getIntFromMap(Map&lt;String, Object&gt; map, String key) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; if (key == "" || key == null) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 0;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; if (map.get(key) == null) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 0;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; return Integer.parseInt((String) map.get(key));</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; /**</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;* 打log接口</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;* @param log 要打印的log字符串</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;* @return 返回log</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;*/</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; public static String log(Object log){</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; return log.toString();</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; /**</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;* 读取本地的xml数据，一般用来自测用</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;* @param localPath 本地xml文件路径</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;* @return 读到的xml字符串</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;*/</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; public static String getLocalXMLString(String localPath) throws IOException {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; return Util.inputStreamToString(Util.class.getResourceAsStream(localPath));</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; /**</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;* 将java对象转为xml字符串</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;* @param clazz</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;* @return</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;*/</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; public static String bean2XML(Object o){</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;xstream.alias("xml", o.getClass());</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;return xstream.toXML(o);</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; /**</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; * 扩展xstream，使其支持CDATA块</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; * &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; * @date 2013-05-19</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; */ &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;private static XStream xstream = new XStream(new XppDriver() { &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;public HierarchicalStreamWriter createWriter(Writer out) { &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return new PrettyPrintWriter(out) { &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// 对所有xml节点的转换都增加CDATA标记 &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;boolean cdata = true; &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@SuppressWarnings("unchecked") &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public void startNode(String name, Class clazz) { &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;super.startNode(name, clazz); &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;protected void writeText(QuickWriter writer, String text) { &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (cdata) { &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writer.write("&lt;![CDATA["); &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writer.write(text); &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writer.write("]]&gt;"); &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else { &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writer.write(text); &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}; &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;} &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;}); &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">到这一步，已经完成了最终要发送出去的数据，然后是写http请求方法。</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">声明：工具类代码参考微信支付开发的demo，有些自己做了小改动。</span></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">PS:需要引入xstream-1.3.1.jar包，大家可以去apache中央仓库找<a href="https://repository.sonatype.org/" style="cursor: pointer;">https://repository.sonatype.org</a>，输入xstream就可以搜索到，并下载出来，如果你的项目是maven建立的，直接在pom.xml里面加上就行</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&lt;dependency&gt;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;&lt;groupId&gt;com.thoughtworks.xstream&lt;/groupId&gt;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;&lt;artifactId&gt;xstream&lt;/artifactId&gt;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;&lt;version&gt;1.3.1&lt;/version&gt;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&lt;/dependency&gt;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><img src ="http://www.blogjava.net/resteater/aggbug/427271.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/resteater/" target="_blank">休息食客</a> 2015-09-11 15:46 <a href="http://www.blogjava.net/resteater/archive/2015/09/11/427271.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>微信现金红包开发1（JAVA）</title><link>http://www.blogjava.net/resteater/archive/2015/09/10/427248.html</link><dc:creator>休息食客</dc:creator><author>休息食客</author><pubDate>Thu, 10 Sep 2015 07:35:00 GMT</pubDate><guid>http://www.blogjava.net/resteater/archive/2015/09/10/427248.html</guid><wfw:comment>http://www.blogjava.net/resteater/comments/427248.html</wfw:comment><comments>http://www.blogjava.net/resteater/archive/2015/09/10/427248.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/resteater/comments/commentRss/427248.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/resteater/services/trackbacks/427248.html</trackback:ping><description><![CDATA[<span style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">开发之前，最好有一些微信开发的经验，先看一下文档，了解一下</span><a href="https://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=13_5" style="cursor: pointer; font-family: 微软雅黑; widows: auto; background-color: #ffffff;">https://pay.weixin.qq.com/wiki/doc/api/cash_coupon.php?chapter=13_5</a><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">文档过了一遍之后，脑海里应该有些印象了，废话不说，进入开发。</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">准备参数，一个一个来。</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">参数1：随机字符串 &nbsp; &nbsp;<span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">nonce_str</span><br style="background-color: inherit;" /><div style="background-color: inherit;"></div></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">//获取随机数,这里设定长度20,只要不成长于32位</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">String nonce_str = RandomStringGenerator.getRandomStringByLength(20);&nbsp;</span></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;"><br style="background-color: inherit;" /></span></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">写一个RandomStringGenerator类，写一个getRandomStringByLength静态方法</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">import java.util.Random;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">/**</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;* User: rizenguo</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;* Date: 2014/10/29</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp;*/</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">public class RandomStringGenerator {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; /**</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;* 获取一定长度的随机字符串</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;* @param length 指定字符串长度</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;* @return 一定长度的字符串</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;*/</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; public static String getRandomStringByLength(int length) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; String base = "abcdefghijklmnopqrstuvwxyz0123456789";</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; Random random = new Random();</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; StringBuffer sb = new StringBuffer();</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i &lt; length; i++) {</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int number = random.nextInt(base.length());</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sb.append(base.charAt(number));</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; &nbsp; return sb.toString();</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">&nbsp; &nbsp; }</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">}</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"></div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">参数2 ：&nbsp;商户号 &nbsp;&nbsp;mch_id</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;">String mch_id = &#8220;xxxxxxxx&#8221;;</div><div style="font-family: 微软雅黑; widows: auto; background-color: #ffffff;"><div style="background-color: inherit;"><img src="file:///C:/Documents%20and%20Settings/lb/Local%20Settings/Application%20Data/YNote/data/tclobbyer@163.com/ee8fd967b8764c46a330ebc1c59424ff/j%25sbr5%5Bm40nw.png" data-media-type="image" data-attr-org-src-id="91F0A2992DFC4197A82799ADEEE8812B" data-attr-org-img-file="file:///C:/Documents%20and%20Settings/lb/Local%20Settings/Application%20Data/YNote/data/tclobbyer@163.com/ee8fd967b8764c46a330ebc1c59424ff/j%25sbr5%5Bm40nw.png" style="background-color: inherit; cursor: default; display: inline-block; margin-top: 8px; max-width: 800px;"  alt="" /></div><div style="background-color: inherit;"></div><div style="background-color: inherit;"><img src="http://www.blogjava.net/images/blogjava_net/resteater/QQ图片20150910153338.png" width="768" height="653" alt="" /></div><div style="background-color: inherit;"><br />参数3 ：&nbsp;<span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">商户订单号 &nbsp;mch_billno</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;"><br style="background-color: inherit;" /></span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">String mch_billno = mch_id + GenerateSequenceUtil.generateSequenceNo();</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;"><br style="background-color: inherit;" /></span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">些一个GenerateSequenceUtil类，写一个generateSequenceNo方法</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;"><br style="background-color: inherit;" /></span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">import java.text.DecimalFormat;</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">import java.text.FieldPosition;</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">import java.text.Format;</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">import java.text.NumberFormat;</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">import java.text.SimpleDateFormat;</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">import java.util.Calendar;</span></div><div style="background-color: inherit;">&nbsp;</div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">import org.apache.log4j.Logger;</span></div><div style="background-color: inherit;">&nbsp;</div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">public class GenerateSequenceUtil {</span></div><div style="background-color: inherit;">&nbsp;</div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp;/** .log */</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp;private static final Logger logger = Logger.getLogger(GenerateSequenceUtil.class);</span></div><div style="background-color: inherit;">&nbsp;</div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp;/** The FieldPosition. */</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp;private static final FieldPosition HELPER_POSITION = new FieldPosition(0);</span></div><div style="background-color: inherit;">&nbsp;</div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp;/** This Format for format the data to special format. */</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp;private final static Format dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");</span></div><div style="background-color: inherit;">&nbsp;</div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp;/** This Format for format the number to special format. */</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp;private final static NumberFormat numberFormat = new DecimalFormat("0000");</span></div><div style="background-color: inherit;">&nbsp;</div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp;/** This int is the sequence number ,the default value is 0. */</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp;private static int seq = 0;</span></div><div style="background-color: inherit;">&nbsp;</div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp;private static final int MAX = 9999;</span></div><div style="background-color: inherit;">&nbsp;</div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp;/**</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp;* 时间格式生成序列</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp;* @return String</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp;*/</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp;public static synchronized String generateSequenceNo() {</span></div><div style="background-color: inherit;">&nbsp;</div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp; Calendar rightNow = Calendar.getInstance();</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp; &nbsp;</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp; StringBuffer sb = new StringBuffer();</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp; &nbsp;</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp; dateFormat.format(rightNow.getTime(), sb, HELPER_POSITION);</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp; &nbsp;</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp; numberFormat.format(seq, sb, HELPER_POSITION);</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp; &nbsp;</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp; if (seq == MAX) {</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp; &nbsp;seq = 0;</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp; } else {</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp; &nbsp;seq++;</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp; }</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp; &nbsp;</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp; logger.info("THE SQUENCE IS :" + sb.toString());</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp; &nbsp;</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp; return sb.toString();</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">&nbsp;}</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;"><br style="background-color: inherit;" /></span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">参数4：&nbsp;公众账号appid &nbsp;&nbsp;wxappid</span></div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;"><br style="background-color: inherit;" /></span></div><div style="background-color: inherit;">这个参数可以在微信开发者中心里面看到</div><div style="background-color: inherit;"><span style="color: #222222; font-family: 'Helvetica Neue', 'Hiragino Sans GB', 'Microsoft YaHei', 黑体, Arial, sans-serif;">//微信分配的公众账号ID</span></div><div style="background-color: inherit;">String&nbsp;wxappid = "wx8888888888888888";</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">参数5 ：&nbsp;商户名称 &nbsp;&nbsp;send_name</div><div style="background-color: inherit;">随便写</div><div style="background-color: inherit;">String send_name = "测试者"; &nbsp;&nbsp;</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">参数6 ：&nbsp;用户openid &nbsp;&nbsp;re_openid</div><div style="background-color: inherit;">微信号和公众号对应的唯一的加密过的字符串</div><div style="background-color: inherit;">String&nbsp;re_openid = "xxxxxxxxxxxxxxxxxxxxxxx";</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">参数7：&nbsp;付款金额 &nbsp;&nbsp;total_amount</div><div style="background-color: inherit;">int total_amount = 100; &nbsp; &nbsp;单位分</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">参数8 ：&nbsp;红包发放总人数 &nbsp;total_num</div><div style="background-color: inherit;">int total_num = 1;</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">参数9 ：&nbsp;红包祝福语 &nbsp;&nbsp;wishing</div><div style="background-color: inherit;">随便写</div><div style="background-color: inherit;">String wishing = "测试";</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">参数10 ：&nbsp;Ip地址 &nbsp;&nbsp;client_ip</div><div style="background-color: inherit;">String client_ip = InetAddress.getLocalHost().getHostAddress().toString();</div><div style="background-color: inherit;">这里可能报异常，需要抓取一下</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">参数11 ：&nbsp;活动名称 &nbsp;&nbsp;act_name</div><div style="background-color: inherit;">随便写</div><div style="background-color: inherit;">String act_name = "测试创建20150906";</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">参数12 ：&nbsp;备注 &nbsp;remark</div><div style="background-color: inherit;">随便写</div><div style="background-color: inherit;">String remark = "测试";</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">最后一个参数sign</div><div style="background-color: inherit;">//签名</div><div style="background-color: inherit;">&nbsp; Map&lt;String,Object&gt; map = new HashMap&lt;String,Object&gt;();</div><div style="background-color: inherit;">&nbsp; map.put("nonce_str", nonce_str);</div><div style="background-color: inherit;">&nbsp; map.put("mch_billno", mch_billno);</div><div style="background-color: inherit;">&nbsp; map.put("mch_id", mch_id);</div><div style="background-color: inherit;">&nbsp; map.put("wxappid", wxappid);</div><div style="background-color: inherit;">&nbsp; map.put("send_name", send_name);</div><div style="background-color: inherit;">&nbsp; map.put("re_openid", re_openid);</div><div style="background-color: inherit;">&nbsp; map.put("total_amount", total_amount);</div><div style="background-color: inherit;">&nbsp; map.put("total_num", total_num);</div><div style="background-color: inherit;">&nbsp; map.put("wishing", wishing);</div><div style="background-color: inherit;">&nbsp; map.put("client_ip", client_ip);</div><div style="background-color: inherit;">&nbsp; map.put("act_name", act_name);</div><div style="background-color: inherit;">&nbsp; map.put("remark", remark);</div><div style="background-color: inherit;">&nbsp; String sign = Signature.getSign(map);</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">写一个Signature类，代码如下：</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">import org.xml.sax.SAXException;</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">import com.yxht.core.common.tools.LoadProperties;</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">import javax.xml.parsers.ParserConfigurationException;</div><div style="background-color: inherit;">import java.io.IOException;</div><div style="background-color: inherit;">import java.lang.reflect.Field;</div><div style="background-color: inherit;">import java.util.ArrayList;</div><div style="background-color: inherit;">import java.util.Arrays;</div><div style="background-color: inherit;">import java.util.Map;</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">/**</div><div style="background-color: inherit;">&nbsp;* User: rizenguo</div><div style="background-color: inherit;">&nbsp;* Date: 2014/10/29</div><div style="background-color: inherit;">&nbsp;* Time: 15:23</div><div style="background-color: inherit;">&nbsp;*/</div><div style="background-color: inherit;">public class Signature {</div><div style="background-color: inherit;">&nbsp; &nbsp; /**</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;* 签名算法</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;* @param o 要参与签名的数据对象</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;* @return 签名</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;* @throws IllegalAccessException</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;*/</div><div style="background-color: inherit;">&nbsp; &nbsp; public static String getSign(Object o) throws IllegalAccessException {</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; Class cls = o.getClass();</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; Field[] fields = cls.getDeclaredFields();</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; for (Field f : fields) {</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f.setAccessible(true);</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (f.get(o) != null &amp;&amp; f.get(o) != "") {</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; list.add(f.getName() + "=" + f.get(o) + "&amp;");</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; int size = list.size();</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; String [] arrayToSort = list.toArray(new String[size]);</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER);</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; StringBuilder sb = new StringBuilder();</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; for(int i = 0; i &lt; size; i ++) {</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sb.append(arrayToSort[i]);</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; String result = sb.toString();</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; result += "key=" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; &nbsp; //这里是开发者中心里面服务器配置里面的消息加解密密钥</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; Util.log("Sign Before MD5:" + result);</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; result = MD5.MD5Encode(result).toUpperCase();</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; Util.log("Sign Result:" + result);</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; return result;</div><div style="background-color: inherit;">&nbsp; &nbsp; }</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">&nbsp; &nbsp; public static String getSign(Map&lt;String,Object&gt; map){</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; for(Map.Entry&lt;String,Object&gt; entry:map.entrySet()){</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(entry.getValue()!=""){</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; list.add(entry.getKey() + "=" + entry.getValue() + "&amp;");</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; int size = list.size();</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; String [] arrayToSort = list.toArray(new String[size]);</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER);</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; StringBuilder sb = new StringBuilder();</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; for(int i = 0; i &lt; size; i ++) {</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sb.append(arrayToSort[i]);</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; String result = sb.toString();</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; result += "key=" + LoadProperties.getSystemdefaultValue("APP_KEY");</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; result = MD5.MD5Encode(result).toUpperCase();</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; return result;</div><div style="background-color: inherit;">&nbsp; &nbsp; }</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">&nbsp; &nbsp; /**</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;* 从API返回的XML数据里面重新计算一次签名</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;* @param responseString API返回的XML数据</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;* @return 新鲜出炉的签名</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;* @throws ParserConfigurationException</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;* @throws IOException</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;* @throws SAXException</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;*/</div><div style="background-color: inherit;">&nbsp; &nbsp; public static String getSignFromResponseString(String responseString) throws IOException, SAXException, ParserConfigurationException {</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; Map&lt;String,Object&gt; map = XMLParser.getMapFromXML(responseString);</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; //清掉返回数据对象里面的Sign数据（不能把这个数据也加进去进行签名），然后用签名算法进行签名</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; map.put("sign","");</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; //将API返回的数据根据用签名算法进行计算新的签名，用来跟API返回的签名进行比较</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; return Signature.getSign(map);</div><div style="background-color: inherit;">&nbsp; &nbsp; }</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">&nbsp; &nbsp; /**</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;* 检验API返回的数据里面的签名是否合法，避免数据在传输的过程中被第三方篡改</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;* @param responseString API返回的XML数据字符串</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;* @return API签名是否合法</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;* @throws ParserConfigurationException</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;* @throws IOException</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;* @throws SAXException</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp;*/</div><div style="background-color: inherit;">&nbsp; &nbsp; public static boolean checkIsSignValidFromResponseString(String responseString) throws ParserConfigurationException, IOException, SAXException {</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; Map&lt;String,Object&gt; map = XMLParser.getMapFromXML(responseString);</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; Util.log(map.toString());</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; String signFromAPIResponse = map.get("sign").toString();</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; if(signFromAPIResponse=="" || signFromAPIResponse == null){</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Util.log("API返回的数据签名数据不存在，有可能被第三方篡改!!!");</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; Util.log("服务器回包里面的签名是:" + signFromAPIResponse);</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; //清掉返回数据对象里面的Sign数据（不能把这个数据也加进去进行签名），然后用签名算法进行签名</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; map.put("sign","");</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; //将API返回的数据根据用签名算法进行计算新的签名，用来跟API返回的签名进行比较</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; String signForAPIResponse = Signature.getSign(map);</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; if(!signForAPIResponse.equals(signFromAPIResponse)){</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //签名验不过，表示这个API返回的数据有可能已经被篡改了</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Util.log("API返回的数据签名验证不通过，有可能被第三方篡改!!!");</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; Util.log("恭喜，API返回的数据签名验证通过!!!");</div><div style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; return true;</div><div style="background-color: inherit;">&nbsp; &nbsp; }</div><div style="background-color: inherit;"></div><div style="background-color: inherit;">}</div><div style="background-color: inherit;"></div><div style="background-color: inherit;"></div><div style="background-color: inherit;">先讲到这里，所有参数都准备好了，下一步是组成xml</div><div style="background-color: inherit;"></div><div style="background-color: inherit;"></div><div style="background-color: inherit;">声明：工具类代码参考微信支付开发的demo，有些自己做了小改动。</div></div><img src ="http://www.blogjava.net/resteater/aggbug/427248.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/resteater/" target="_blank">休息食客</a> 2015-09-10 15:35 <a href="http://www.blogjava.net/resteater/archive/2015/09/10/427248.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java解析xml文件（dom4j方式）</title><link>http://www.blogjava.net/resteater/archive/2015/02/11/422872.html</link><dc:creator>休息食客</dc:creator><author>休息食客</author><pubDate>Wed, 11 Feb 2015 09:23:00 GMT</pubDate><guid>http://www.blogjava.net/resteater/archive/2015/02/11/422872.html</guid><wfw:comment>http://www.blogjava.net/resteater/comments/422872.html</wfw:comment><comments>http://www.blogjava.net/resteater/archive/2015/02/11/422872.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/resteater/comments/commentRss/422872.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/resteater/services/trackbacks/422872.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: java解析xml文件的方式有几种，下面介绍用dom4j方式解析1、先看一段xml内容 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->&nbsp;&nbsp;1&nbsp;&lt;configs&gt;&nbsp;&nbsp;2&nbsp;&nb...&nbsp;&nbsp;<a href='http://www.blogjava.net/resteater/archive/2015/02/11/422872.html'>阅读全文</a><img src ="http://www.blogjava.net/resteater/aggbug/422872.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/resteater/" target="_blank">休息食客</a> 2015-02-11 17:23 <a href="http://www.blogjava.net/resteater/archive/2015/02/11/422872.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java获取根目录，读取配置文件</title><link>http://www.blogjava.net/resteater/archive/2015/01/30/422583.html</link><dc:creator>休息食客</dc:creator><author>休息食客</author><pubDate>Fri, 30 Jan 2015 07:01:00 GMT</pubDate><guid>http://www.blogjava.net/resteater/archive/2015/01/30/422583.html</guid><wfw:comment>http://www.blogjava.net/resteater/comments/422583.html</wfw:comment><comments>http://www.blogjava.net/resteater/archive/2015/01/30/422583.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/resteater/comments/commentRss/422583.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/resteater/services/trackbacks/422583.html</trackback:ping><description><![CDATA[<div><font style="background-color: #cfe2de">Java获取根目录路径有很多种方法，但是根据应用程序所部署的环境和中间件不同，获取的路径可能也不同。下面我提供一种方法，解决这个问题。<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String path = InterfaceConfig.class.getResource("").getPath().toString();//获取类所在路径<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;if (path.contains(".jar")) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; path = path.replace("/", File.separator);//将/换成\，如果是linux环境，还是/<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; path = path.replace("file:", "");//去掉file<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; path = path.replace("classes\\", "");//去掉classes\<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; if (path.startsWith("\\")) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; path = path.substring(1);//去掉第一个\,如：、\D:\TongWeb...&nbsp; ,在linux上没有这种情况<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; path = path.split("WEB-INF")[0]+"WEB-INF"+File.separator+"classes";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; path = InterfaceConfig.class.getResource("/").getPath().toString();//获取根路径<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File file = new File(path + File.separator + "InterfaceConfig.xml");<br /><br />这段代码什么意思呢？<br />1、第一行是获取InterfaceConfig.class这个类所在的路径，这个InterfaceConfig.class可以换成你这段代码所在的类。<br />2、判断路径中是否包含.jar，就是说这段代码所在的类最终构建的时候是不是打入jar包里，如果在jar包里，就去掉一些内容，如file:&nbsp;,classes\\,<br />&nbsp;&nbsp;&nbsp; 然后根据WEB-INF切割，并拼出根目录。<br />3、如果没有打入jar包，那更简单了，直接通过获取根路径方法就解决了。<br />4、最后读取classes路径下的InterfaceConfig.xml配置文件。<br /><br /></font></div> <img src ="http://www.blogjava.net/resteater/aggbug/422583.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/resteater/" target="_blank">休息食客</a> 2015-01-30 15:01 <a href="http://www.blogjava.net/resteater/archive/2015/01/30/422583.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JAVA解析内容格式为XML的字符串</title><link>http://www.blogjava.net/resteater/archive/2014/09/28/418355.html</link><dc:creator>休息食客</dc:creator><author>休息食客</author><pubDate>Sun, 28 Sep 2014 07:01:00 GMT</pubDate><guid>http://www.blogjava.net/resteater/archive/2014/09/28/418355.html</guid><wfw:comment>http://www.blogjava.net/resteater/comments/418355.html</wfw:comment><comments>http://www.blogjava.net/resteater/archive/2014/09/28/418355.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/resteater/comments/commentRss/418355.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/resteater/services/trackbacks/418355.html</trackback:ping><description><![CDATA[<p>假如有一个字符串的内容是xml格式，如：</p>
<p>&nbsp;</p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;aa&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;row&gt;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;user&gt;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;userid&gt;1000&lt;/userid&gt;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;username&gt;aaa&lt;/username&gt;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;/user&gt;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;user&gt;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;userid&gt;1001&lt;/userid&gt;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;username&gt;bbb&lt;/username&gt;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;/user&gt;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;/row&gt;</span><span style="color: #000000">"</span><span style="color: #000000">;</span></div>
<p>这是一个字符串，不是一个XML文档，只是该字符串里面的内容是XML格式，该怎么解析呢？<br />假如我有一个User对象，有userid和username属性，然后把该字符串里面的数据解析到User对象来。<br />思路：把该字符串先解析为docment树形文档，然后获取根元素row，再然后获取根元素的第一个子元素user,然后获取user元素的第一个子元素userid并把该值存入user对象里<br />看代码：</p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.util.ArrayList;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.util.Iterator;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;java.util.List;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;org.dom4j.Document;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;org.dom4j.DocumentException;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;org.dom4j.DocumentHelper;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000">&nbsp;org.dom4j.Element;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" /><br /><img id="Codehighlighter1_220_1889_Open_Image" onclick="this.style.display='none'; Codehighlighter1_220_1889_Open_Text.style.display='none'; Codehighlighter1_220_1889_Closed_Image.style.display='inline'; Codehighlighter1_220_1889_Closed_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_220_1889_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_220_1889_Closed_Text.style.display='none'; Codehighlighter1_220_1889_Open_Image.style.display='inline'; Codehighlighter1_220_1889_Open_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;test&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_220_1889_Closed_Text"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_220_1889_Open_Text"><span style="color: #000000">{&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img id="Codehighlighter1_225_248_Open_Image" onclick="this.style.display='none'; Codehighlighter1_225_248_Open_Text.style.display='none'; Codehighlighter1_225_248_Closed_Image.style.display='inline'; Codehighlighter1_225_248_Closed_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_225_248_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_225_248_Closed_Text.style.display='none'; Codehighlighter1_225_248_Open_Image.style.display='inline'; Codehighlighter1_225_248_Open_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_225_248_Closed_Text">/**&nbsp;*/</span><span id="Codehighlighter1_225_248_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span style="color: #808080">@param</span><span style="color: #008000">&nbsp;args<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /><img id="Codehighlighter1_290_868_Open_Image" onclick="this.style.display='none'; Codehighlighter1_290_868_Open_Text.style.display='none'; Codehighlighter1_290_868_Closed_Image.style.display='inline'; Codehighlighter1_290_868_Closed_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_290_868_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_290_868_Closed_Text.style.display='none'; Codehighlighter1_290_868_Open_Image.style.display='inline'; Codehighlighter1_290_868_Open_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;main(String[]&nbsp;args)&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_290_868_Closed_Text"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_290_868_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;TODO&nbsp;Auto-generated&nbsp;method&nbsp;stub</span><span style="color: #008000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;aa&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;row&gt;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;user&gt;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;userid&gt;1000&lt;/userid&gt;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;username&gt;aaa&lt;/username&gt;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;/user&gt;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;user&gt;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;userid&gt;1001&lt;/userid&gt;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;username&gt;bbb&lt;/username&gt;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;/user&gt;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&lt;/row&gt;</span><span style="color: #000000">"</span><span style="color: #000000">;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;test&nbsp;t&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;test();<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List</span><span style="color: #000000">&lt;</span><span style="color: #000000">User</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;lu&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;ArrayList</span><span style="color: #000000">&lt;</span><span style="color: #000000">User</span><span style="color: #000000">&gt;</span><span style="color: #000000">();<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;User&nbsp;user&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;User();<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lu&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;t.Analysis(aa,&nbsp;lu,&nbsp;user);<br /><img id="Codehighlighter1_798_865_Open_Image" onclick="this.style.display='none'; Codehighlighter1_798_865_Open_Text.style.display='none'; Codehighlighter1_798_865_Closed_Image.style.display='inline'; Codehighlighter1_798_865_Closed_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_798_865_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_798_865_Closed_Text.style.display='none'; Codehighlighter1_798_865_Open_Image.style.display='inline'; Codehighlighter1_798_865_Open_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(User&nbsp;u&nbsp;:&nbsp;lu)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_798_865_Closed_Text"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_798_865_Open_Text"><span style="color: #000000">{;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(u.getUserid()</span><span style="color: #000000">+</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">+</span><span style="color: #000000">u.getUsername());<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;<br /><img id="Codehighlighter1_886_892_Open_Image" onclick="this.style.display='none'; Codehighlighter1_886_892_Open_Text.style.display='none'; Codehighlighter1_886_892_Closed_Image.style.display='inline'; Codehighlighter1_886_892_Closed_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_886_892_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_886_892_Closed_Text.style.display='none'; Codehighlighter1_886_892_Open_Image.style.display='inline'; Codehighlighter1_886_892_Open_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;test()</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_886_892_Closed_Text"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_886_892_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;<br /><img id="Codehighlighter1_957_1886_Open_Image" onclick="this.style.display='none'; Codehighlighter1_957_1886_Open_Text.style.display='none'; Codehighlighter1_957_1886_Closed_Image.style.display='inline'; Codehighlighter1_957_1886_Closed_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_957_1886_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_957_1886_Closed_Text.style.display='none'; Codehighlighter1_957_1886_Open_Image.style.display='inline'; Codehighlighter1_957_1886_Open_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;List</span><span style="color: #000000">&lt;</span><span style="color: #000000">User</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;Analysis(String&nbsp;s,List</span><span style="color: #000000">&lt;</span><span style="color: #000000">User</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;lu,User&nbsp;user)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_957_1886_Closed_Text"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_957_1886_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Document&nbsp;doc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img id="Codehighlighter1_992_1055_Open_Image" onclick="this.style.display='none'; Codehighlighter1_992_1055_Open_Text.style.display='none'; Codehighlighter1_992_1055_Closed_Image.style.display='inline'; Codehighlighter1_992_1055_Closed_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_992_1055_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_992_1055_Closed_Text.style.display='none'; Codehighlighter1_992_1055_Open_Image.style.display='inline'; Codehighlighter1_992_1055_Open_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">try</span><span style="color: #000000">&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_992_1055_Closed_Text"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_992_1055_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doc&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;DocumentHelper.parseText(s);</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;将字符串转为document树形格式</span><span style="color: #008000"><br /><img id="Codehighlighter1_1085_1113_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1085_1113_Open_Text.style.display='none'; Codehighlighter1_1085_1113_Closed_Image.style.display='inline'; Codehighlighter1_1085_1113_Closed_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1085_1113_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1085_1113_Closed_Text.style.display='none'; Codehighlighter1_1085_1113_Open_Image.style.display='inline'; Codehighlighter1_1085_1113_Open_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif"></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">catch</span><span style="color: #000000">&nbsp;(DocumentException&nbsp;e)&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1085_1113_Closed_Text"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1085_1113_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Element&nbsp;rootElt&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;doc.getRootElement();&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;获取根节点</span><span style="color: #008000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Iterator&nbsp;iter&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;rootElt.elementIterator(</span><span style="color: #000000">"</span><span style="color: #000000">user</span><span style="color: #000000">"</span><span style="color: #000000">);&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;获取根节点下的子节点user</span><span style="color: #008000"><br /><img id="Codehighlighter1_1263_1869_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1263_1869_Open_Text.style.display='none'; Codehighlighter1_1263_1869_Closed_Image.style.display='inline'; Codehighlighter1_1263_1869_Closed_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1263_1869_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1263_1869_Closed_Text.style.display='none'; Codehighlighter1_1263_1869_Open_Image.style.display='inline'; Codehighlighter1_1263_1869_Open_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif"></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">&nbsp;(iter.hasNext())&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1263_1869_Closed_Text"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1263_1869_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;user&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;User();<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Element&nbsp;recordEle&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(Element)&nbsp;iter.next();<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Iterator&nbsp;iters&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;recordEle.elementIterator(</span><span style="color: #000000">"</span><span style="color: #000000">userid</span><span style="color: #000000">"</span><span style="color: #000000">);&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;获取子节点user下的子节点userId</span><span style="color: #008000"><br /><img id="Codehighlighter1_1466_1597_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1466_1597_Open_Text.style.display='none'; Codehighlighter1_1466_1597_Closed_Image.style.display='inline'; Codehighlighter1_1466_1597_Closed_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1466_1597_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1466_1597_Closed_Text.style.display='none'; Codehighlighter1_1466_1597_Open_Image.style.display='inline'; Codehighlighter1_1466_1597_Open_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif"></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(iters.hasNext())</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1466_1597_Closed_Text"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1466_1597_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Element&nbsp;userId&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(Element)&nbsp;iters.next();<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;user.setUserid(Long.parseLong(userId.getText()));<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iters&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;recordEle.elementIterator(</span><span style="color: #000000">"</span><span style="color: #000000">username</span><span style="color: #000000">"</span><span style="color: #000000">);&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;获取子节点user下的子节点username</span><span style="color: #008000"><br /><img id="Codehighlighter1_1718_1839_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1718_1839_Open_Text.style.display='none'; Codehighlighter1_1718_1839_Closed_Image.style.display='inline'; Codehighlighter1_1718_1839_Closed_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1718_1839_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1718_1839_Closed_Text.style.display='none'; Codehighlighter1_1718_1839_Open_Image.style.display='inline'; Codehighlighter1_1718_1839_Open_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif"></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(iters.hasNext())</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1718_1839_Closed_Text"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1718_1839_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Element&nbsp;username&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;(Element)&nbsp;iters.next();<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;user.setUsername(username.getText());<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lu.add(user);<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;lu;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" /><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/None.gif"  alt="" /><br /><img id="Codehighlighter1_1903_2194_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1903_2194_Open_Text.style.display='none'; Codehighlighter1_1903_2194_Closed_Image.style.display='inline'; Codehighlighter1_1903_2194_Closed_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_1903_2194_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1903_2194_Closed_Text.style.display='none'; Codehighlighter1_1903_2194_Open_Image.style.display='inline'; Codehighlighter1_1903_2194_Open_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;User&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1903_2194_Closed_Text"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1903_2194_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;Long&nbsp;userid;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;String&nbsp;username;<br /><img id="Codehighlighter1_1978_1998_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1978_1998_Open_Text.style.display='none'; Codehighlighter1_1978_1998_Closed_Image.style.display='inline'; Codehighlighter1_1978_1998_Closed_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1978_1998_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1978_1998_Closed_Text.style.display='none'; Codehighlighter1_1978_1998_Open_Image.style.display='inline'; Codehighlighter1_1978_1998_Open_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;Long&nbsp;getUserid()&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1978_1998_Closed_Text"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1978_1998_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;userid;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img id="Codehighlighter1_2036_2063_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2036_2063_Open_Text.style.display='none'; Codehighlighter1_2036_2063_Closed_Image.style.display='inline'; Codehighlighter1_2036_2063_Closed_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_2036_2063_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_2036_2063_Closed_Text.style.display='none'; Codehighlighter1_2036_2063_Open_Image.style.display='inline'; Codehighlighter1_2036_2063_Open_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;setUserid(Long&nbsp;userid)&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_2036_2063_Closed_Text"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_2036_2063_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.userid&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;userid;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img id="Codehighlighter1_2094_2116_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2094_2116_Open_Text.style.display='none'; Codehighlighter1_2094_2116_Closed_Image.style.display='inline'; Codehighlighter1_2094_2116_Closed_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_2094_2116_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_2094_2116_Closed_Text.style.display='none'; Codehighlighter1_2094_2116_Open_Image.style.display='inline'; Codehighlighter1_2094_2116_Open_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;String&nbsp;getUsername()&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_2094_2116_Closed_Text"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_2094_2116_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;username;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /><img id="Codehighlighter1_2160_2191_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2160_2191_Open_Text.style.display='none'; Codehighlighter1_2160_2191_Closed_Image.style.display='inline'; Codehighlighter1_2160_2191_Closed_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_2160_2191_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_2160_2191_Closed_Text.style.display='none'; Codehighlighter1_2160_2191_Open_Image.style.display='inline'; Codehighlighter1_2160_2191_Open_Text.style.display='inline';" align="top" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;setUsername(String&nbsp;username)&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_2160_2191_Closed_Text"><img src="http://www.blogjava.net/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_2160_2191_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">this</span><span style="color: #000000">.username&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;username;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;<br /><img align="top" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span></div>
<p>整个解析过程及思路在Analysis方法里面，注释写清楚了，可以自己去琢磨！<br /></p> <img src ="http://www.blogjava.net/resteater/aggbug/418355.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/resteater/" target="_blank">休息食客</a> 2014-09-28 15:01 <a href="http://www.blogjava.net/resteater/archive/2014/09/28/418355.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Maven+jetty启动配置</title><link>http://www.blogjava.net/resteater/archive/2014/09/20/418116.html</link><dc:creator>休息食客</dc:creator><author>休息食客</author><pubDate>Sat, 20 Sep 2014 06:04:00 GMT</pubDate><guid>http://www.blogjava.net/resteater/archive/2014/09/20/418116.html</guid><wfw:comment>http://www.blogjava.net/resteater/comments/418116.html</wfw:comment><comments>http://www.blogjava.net/resteater/archive/2014/09/20/418116.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/resteater/comments/commentRss/418116.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/resteater/services/trackbacks/418116.html</trackback:ping><description><![CDATA[<div>当我们的j2ee项目建好后，如果用jetty启动，要怎么配置呢？<br />直接打开项目的pom.xml文件，添加如下配置：<br />&lt;plugins&gt;<br />&lt;plugin&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;artifactId&gt;maven-jetty-plugin&lt;/artifactId&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;version&gt;6.1.26&lt;/version&gt;<br />&lt;/plugin&gt;<br />&lt;/plugins&gt;<br />注意：这段配置在你复制到pom.xml文件里的时候，应该放在&lt;build&gt;&lt;/build&gt;里面，如<br /><div>&lt;build&gt;</div><div>&nbsp; &nbsp; &lt;finalName&gt;WechatTest_Core&lt;/finalName&gt;</div><div>&nbsp; &nbsp; &lt;plugins&gt;</div><div><span style="white-space:pre">		</span>&lt;plugin&gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;artifactId&gt;maven-jetty-plugin&lt;/artifactId&gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;version&gt;6.1.26&lt;/version&gt;</div><div><span style="white-space:pre">		</span>&lt;/plugin&gt;</div><div><span style="white-space: pre;">&nbsp;   </span>&lt;/plugins&gt;<br />&nbsp; &nbsp; ....<br />&nbsp; &nbsp; ....</div><div>&nbsp; &lt;/build&gt;</div>说明：该配置的groupId和artifactId不用改变，就是这样，而version具体用哪个版本，可以在中央仓库里找，这里我用的是6.1.26版本，配置好了后保存。<br />接下来是启动项目，第一次要配置一下启动信息，run as-&gt;Run Configurations...<br />如图：<br /><img src="http://www.blogjava.net/images/blogjava_net/resteater/54537/o_20140920140105.jpg" alt="" border="0" height="640" width="1024" /></div>ok了，输入http://localhost:8081/就可以访问了<img src ="http://www.blogjava.net/resteater/aggbug/418116.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/resteater/" target="_blank">休息食客</a> 2014-09-20 14:04 <a href="http://www.blogjava.net/resteater/archive/2014/09/20/418116.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>maven+hibernate3构建项目的pom.xml</title><link>http://www.blogjava.net/resteater/archive/2014/09/07/417740.html</link><dc:creator>休息食客</dc:creator><author>休息食客</author><pubDate>Sat, 06 Sep 2014 17:08:00 GMT</pubDate><guid>http://www.blogjava.net/resteater/archive/2014/09/07/417740.html</guid><wfw:comment>http://www.blogjava.net/resteater/comments/417740.html</wfw:comment><comments>http://www.blogjava.net/resteater/archive/2014/09/07/417740.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/resteater/comments/commentRss/417740.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/resteater/services/trackbacks/417740.html</trackback:ping><description><![CDATA[<p>&lt;project xmlns="<a href="http://maven.apache.org/POM/4.0.0">http://maven.apache.org/POM/4.0.0</a>" xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"<br />&nbsp; xsi:schemaLocation="<a href="http://maven.apache.org/POM/4.0.0">http://maven.apache.org/POM/4.0.0</a> <a href="http://maven.apache.org/xsd/maven-4.0.0.xsd">http://maven.apache.org/xsd/maven-4.0.0.xsd</a>"&gt;<br />&nbsp; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;<br />&lt;!--项目基本信息--&gt;</p><p>&nbsp; &lt;groupId&gt;com.loubing.test&lt;/groupId&gt;<br />&nbsp; &lt;artifactId&gt;myhibernate&lt;/artifactId&gt;<br />&nbsp; &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;<br />&nbsp; &lt;packaging&gt;jar&lt;/packaging&gt;</p><p>&nbsp; &lt;name&gt;myhibernate&lt;/name&gt;<br />&lt;!--依赖包来源，这里是我自己建立的一个私服。也可以用<a href="https://repo1.maven.org/maven2/">https://repo1.maven.org/maven2/</a>&nbsp; --&gt;<br />&nbsp; &lt;url&gt;http://localhost:10000/nexus/content/groups/public&lt;/url&gt;</p><p>&nbsp; &lt;properties&gt;<br />&nbsp;&nbsp;&nbsp; &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;<br />&nbsp; &lt;/properties&gt;</p><p>&nbsp; &lt;dependencies&gt;<br />&nbsp;&nbsp;&nbsp; &lt;dependency&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;groupId&gt;junit&lt;/groupId&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;artifactId&gt;junit&lt;/artifactId&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;version&gt;3.8.1&lt;/version&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;scope&gt;test&lt;/scope&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/dependency&gt;<br />&nbsp;&nbsp;&nbsp; &lt;!-- hibernate --&gt;<br />&nbsp;&nbsp;&nbsp; &lt;dependency&gt;<br />&nbsp;&lt;groupId&gt;c3p0&lt;/groupId&gt;<br />&nbsp;&lt;artifactId&gt;c3p0&lt;/artifactId&gt;<br />&nbsp;&lt;version&gt;0.9.1.2&lt;/version&gt;<br />&nbsp; &lt;/dependency&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp; &lt;!-- 添加Hibernate依赖 --&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &lt;dependency&gt;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;groupId&gt;org.hibernate&lt;/groupId&gt;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;artifactId&gt;hibernate3&lt;/artifactId&gt;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;version&gt;3.0.2&lt;/version&gt;&nbsp; <br />&nbsp;&nbsp;&nbsp; &lt;/dependency&gt;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--以下的包其实可以用hibernate-core，但是我觉得太多了，根据需要，就把几个重要的单独添加进来--&gt;<br />&nbsp;&nbsp;&nbsp; &lt;dependency&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;artifactId&gt;hibernate-jpa-2.0-api&lt;/artifactId&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;version&gt;1.0.1.Final&lt;/version&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/dependency&gt; <br />&nbsp;&nbsp;&nbsp; &lt;dependency&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;groupId&gt;commons-collections&lt;/groupId&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;artifactId&gt;commons-collections&lt;/artifactId&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;version&gt;3.1&lt;/version&gt;<br />&nbsp;&lt;/dependency&gt;<br />&nbsp;&lt;dependency&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;groupId&gt;javax.transaction&lt;/groupId&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;artifactId&gt;jta&lt;/artifactId&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;version&gt;1.1&lt;/version&gt;<br />&nbsp;&lt;/dependency&gt;<br />&nbsp;&nbsp;&nbsp; &lt;dependency&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;groupId&gt;dom4j&lt;/groupId&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;artifactId&gt;dom4j&lt;/artifactId&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;version&gt;1.1&lt;/version&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/dependency&gt;<br />&nbsp;&nbsp;&nbsp; &lt;dependency&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;groupId&gt;org.slf4j&lt;/groupId&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;version&gt;1.4.2&lt;/version&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/dependency&gt;<br />&nbsp;&nbsp;&nbsp; &lt;dependency&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;groupId&gt;org.slf4j&lt;/groupId&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;version&gt;1.4.2&lt;/version&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/dependency&gt;<br />&nbsp;&nbsp;&nbsp; &lt;dependency&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;groupId&gt;javassist&lt;/groupId&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;artifactId&gt;javassist&lt;/artifactId&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;version&gt;3.11.0.GA&lt;/version&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/dependency&gt;<br />&nbsp;&nbsp;&nbsp; &lt;!-- 添加oracle10g jdbc driver --&gt;&nbsp; <br />&nbsp;&nbsp;&nbsp; &lt;dependency&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;groupId&gt;com.oracle&lt;/groupId&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;artifactId&gt;ojdbc14&lt;/artifactId&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;version&gt;10.2.0.1.0&lt;/version&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/dependency&gt;<br />&nbsp; &lt;/dependencies&gt;<br />&lt;/project&gt;<br /></p> 
 <img src ="http://www.blogjava.net/resteater/aggbug/417740.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/resteater/" target="_blank">休息食客</a> 2014-09-07 01:08 <a href="http://www.blogjava.net/resteater/archive/2014/09/07/417740.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>