欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
JAXB解析xml

廢話(huà)不多說(shuō),直接上代碼

核心類(lèi):

package com.jaxb;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.text.MessageFormat;import javax.xml.bind.JAXBContext;import javax.xml.bind.JAXBException;import javax.xml.bind.Unmarshaller;public class JaxbReadXml {    @SuppressWarnings("unchecked")    public static <T> T readString(Class<T> clazz, String context) throws JAXBException {        try {            JAXBContext jc = JAXBContext.newInstance(clazz);            Unmarshaller u = jc.createUnmarshaller();            return (T) u.unmarshal(new File(context));        } catch (JAXBException e) {            // logger.trace(e);            throw e;        }    }    @SuppressWarnings("unchecked")    public static <T> T readConfig(Class<T> clazz, String config, Object... arguments) throws IOException,            JAXBException {        InputStream is = null;        try {            if (arguments.length > 0) {                config = MessageFormat.format(config, arguments);            }            // logger.trace("read configFileName=" + config);            JAXBContext jc = JAXBContext.newInstance(clazz);            Unmarshaller u = jc.createUnmarshaller();            is = new FileInputStream(config);            return (T) u.unmarshal(is);        } catch (IOException e) {            // logger.trace(config, e);            throw e;        } catch (JAXBException e) {            // logger.trace(config, e);            throw e;        } finally {            if (is != null) {                is.close();            }        }    }    @SuppressWarnings("unchecked")    public static <T> T readConfigFromStream(Class<T> clazz, InputStream dataStream) throws JAXBException {        try {            JAXBContext jc = JAXBContext.newInstance(clazz);            Unmarshaller u = jc.createUnmarshaller();            return (T) u.unmarshal(dataStream);        } catch (JAXBException e) {            // logger.trace(e);            throw e;        }    }    public static void main(String[] args) throws JAXBException {        TestOrgs testOrgs = JaxbReadXml.readString(TestOrgs.class, "test/test.xml");        System.out.println(testOrgs.getSize());        System.out.println(testOrgs.getBatchNumber());        System.out.println(testOrgs.getErrmsg());        for (TestOrg o : testOrgs) {            System.out.println(o.getOrgName());        }    }}

 

成員類(lèi):

package com.jaxb;import java.util.ArrayList;import java.util.List;import javax.xml.bind.annotation.XmlAccessType;import javax.xml.bind.annotation.XmlAccessorType;import javax.xml.bind.annotation.XmlAttribute;import javax.xml.bind.annotation.XmlElement;import javax.xml.bind.annotation.XmlRootElement;@SuppressWarnings("serial")@XmlRootElement(name = "orgs")@XmlAccessorType(XmlAccessType.FIELD)public class TestOrgs extends ArrayList<TestOrg> { // 泛化, 聚合    @XmlAttribute(name = "size")    private int size;    @XmlAttribute(name = "batch_number")    private Long batchNumber;    @XmlAttribute(name = "errmsg")    private String errmsg;    @XmlElement(name = "org")    public List<TestOrg> getOrgs() {        return this;    }    public int getSize() {        return size;    }    public void setSize(int size) {        this.size = size;    }    public Long getBatchNumber() {        return batchNumber;    }    public void setBatchNumber(Long batchNumber) {        this.batchNumber = batchNumber;    }    public String getErrmsg() {        return errmsg;    }    public void setErrmsg(String errmsg) {        this.errmsg = errmsg;    }}

 

成員類(lèi)2:

package com.jaxb;import java.util.Date;import javax.xml.bind.annotation.XmlAccessType;import javax.xml.bind.annotation.XmlAccessorType;import javax.xml.bind.annotation.XmlElement;/** * <pre> *     If you annotate your Artifact class with the annotation: *  @XmlAccessorType(XmlAccessType.FIELD) *  then you do not need to annotate the fields with @XmlElement and the *  setter/getter methods will be ignored. * </pre> *  * @author User */@XmlAccessorType(XmlAccessType.FIELD)// 用了這個(gè)之后就會(huì )自動(dòng)忽略setter/getter方法。不用這個(gè)就需要去掉注解,需要保證屬性名和xml里的表簽名一致public class TestOrg {    @XmlElement(name = "org_id")    private Long orgId;    @XmlElement(name = "parent_id")    private Long parentId;    @XmlElement(name = "org_name")    private String orgName;    @XmlElement(name = "org_code")    private String orgCode;    @XmlElement(name = "org_type")    private String orgType;    @XmlElement(name = "start_d")    private Date startDate;    @XmlElement(name = "end_d")    private Date endDate;    @XmlElement(name = "attribute1")    private String attribute;    @XmlElement(name = "insert_t")    private Date insertTime;    public Long getOrgId() {        return orgId;    }    public void setOrgId(Long orgId) {        this.orgId = orgId;    }    public Long getParentId() {        return parentId;    }    public void setParentId(Long parentId) {        this.parentId = parentId;    }    public String getOrgName() {        return orgName;    }    public void setOrgName(String orgName) {        this.orgName = orgName;    }    public String getOrgCode() {        return orgCode;    }    public void setOrgCode(String orgCode) {        this.orgCode = orgCode;    }    public String getOrgType() {        return orgType;    }    public void setOrgType(String orgType) {        this.orgType = orgType;    }    public Date getStartDate() {        return startDate;    }    public void setStartDate(Date startDate) {        this.startDate = startDate;    }    public Date getEndDate() {        return endDate;    }    public void setEndDate(Date endDate) {        this.endDate = endDate;    }    public String getAttribute() {        return attribute;    }    public void setAttribute(String attribute) {        this.attribute = attribute;    }    public Date getInsertTime() {        return insertTime;    }    public void setInsertTime(Date insertTime) {        this.insertTime = insertTime;    }}

xml文件:

<?xml version="1.0" encoding="UTF-8"?><orgs size="7095" batch_number="20130704110039" errmsg="">    <org>        <org_id>16817</org_id>        <parent_id>9233</parent_id>        <org_name>512AAS.蘇州滄浪區</org_name>        <org_code>512AAS</org_code>        <org_type>門(mén)店部門(mén)</org_type>        <start_d>2011-12-28</start_d>        <end_d></end_d>        <attribute1></attribute1>        <insert_t>2013-7-4 10:32:09</insert_t>    </org>    <org>        <org_id>16817</org_id>        <parent_id>9233</parent_id>        <org_name>512AAS.蘇州滄浪區</org_name>        <org_code>512AAS</org_code>        <org_type>門(mén)店部門(mén)</org_type>        <start_d>2011-12-28</start_d>        <end_d></end_d>        <attribute1></attribute1>        <insert_t>2013-7-4 10:32:09</insert_t>    </org>    <org>        <org_id>16817</org_id>        <parent_id>9233</parent_id>        <org_name>512AAS.蘇州滄浪區</org_name>        <org_code>512AAS</org_code>        <org_type>門(mén)店部門(mén)</org_type>        <start_d>2011-12-28</start_d>        <end_d></end_d>        <attribute1></attribute1>        <insert_t>2013-7-4 10:32:09</insert_t>    </org>    <org>        <org_id>16817</org_id>        <parent_id>9233</parent_id>        <org_name>512AAS.蘇州滄浪區</org_name>        <org_code>512AAS</org_code>        <org_type>門(mén)店部門(mén)</org_type>        <start_d>2011-12-28</start_d>        <end_d></end_d>        <attribute1></attribute1>        <insert_t>2013-7-4 10:32:09</insert_t>    </org>    <org>        <org_id>16817</org_id>        <parent_id>9233</parent_id>        <org_name>512AAS.蘇州滄浪區</org_name>        <org_code>512AAS</org_code>        <org_type>門(mén)店部門(mén)</org_type>        <start_d>2011-12-28</start_d>        <end_d></end_d>        <attribute1></attribute1>        <insert_t>2013-7-4 10:32:09</insert_t>    </org></orgs>
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
應用 JAXB 把 XML 轉換成相應的 JavaBean
JAXB完成XML和Java對象的互轉
JAXB--簡(jiǎn)單應用(一)
C#:XML操作類(lèi)
.NET中XML序列化的總結
.NET實(shí)體類(lèi)序列化方法
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久