• XStream xml to bean


    <!-- pom.xml -->
    
    <dependency>
                <groupId>com.thoughtworks.xstream</groupId>
                <artifactId>xstream</artifactId>
                <version>${xstream.version}</version>
            </dependency>
    package demo;
    
    import com.thoughtworks.xstream.annotations.XStreamAlias;
    
    @XStreamAlias("data")
    public class XjdbBean {
        public Message getMessage() {
            return message;
        }
        public void setMessage(Message message) {
            this.message = message;
        }
        public XjCompares getXjCompares() {
            return xjCompares;
        }
        public void setXjCompares(XjCompares xjCompares) {
            this.xjCompares = xjCompares;
        }
        @XStreamAlias("message")
        private Message message;
        @XStreamAlias("xjCompares")
        private XjCompares xjCompares;
    
        @XStreamAlias("xjCompares")
        public static class XjCompares{
            public XjCompare getXjCompare() {
                return xjCompare;
            }
            public void setXjCompare(XjCompare xjCompare) {
                this.xjCompare = xjCompare;
            }
            @XStreamAlias("xjCompare")
            private XjCompare xjCompare;
            
        }
        
        @XStreamAlias("xjCompare")
        public static class XjCompare{
            @XStreamAlias("wybs")
            private String wybs;
            @XStreamAlias("message")
            private Message message;
            @XStreamAlias("yjbyrq")
            private String yjbyrq;
            @XStreamAlias("xllbCheckrs")
            private String xllbCheckrs;
            @XStreamAlias("rxrqCheckrs")
            private String rxrqCheckrs;
            @XStreamAlias("yxmcCheckrs")
            private String yxmcCheckrs;
            @XStreamAlias("ccCheckrs")
            private String ccCheckrs;
            @XStreamAlias("xjCheckrs")
            private String xjCheckrs;
            public String getXllbCheckrs() {
                return xllbCheckrs;
            }
            public void setXllbCheckrs(String xllbCheckrs) {
                this.xllbCheckrs = xllbCheckrs;
            }
            public String getRxrqCheckrs() {
                return rxrqCheckrs;
            }
            public void setRxrqCheckrs(String rxrqCheckrs) {
                this.rxrqCheckrs = rxrqCheckrs;
            }
            public String getYxmcCheckrs() {
                return yxmcCheckrs;
            }
            public void setYxmcCheckrs(String yxmcCheckrs) {
                this.yxmcCheckrs = yxmcCheckrs;
            }
            public String getCcCheckrs() {
                return ccCheckrs;
            }
            public void setCcCheckrs(String ccCheckrs) {
                this.ccCheckrs = ccCheckrs;
            }
            public String getXjCheckrs() {
                return xjCheckrs;
            }
            public void setXjCheckrs(String xjCheckrs) {
                this.xjCheckrs = xjCheckrs;
            }
            public String getWybs() {
                return wybs;
            }
            public void setWybs(String wybs) {
                this.wybs = wybs;
            }
            public Message getMessage() {
                return message;
            }
            public void setMessage(Message message) {
                this.message = message;
            }
            public String getYjbyrq() {
                return yjbyrq;
            }
            public void setYjbyrq(String yjbyrq) {
                this.yjbyrq = yjbyrq;
            }
        }
        
        @XStreamAlias("message")
        public static class Message{
            @XStreamAlias("status")
            private int status;
            @XStreamAlias("value")
            private String value;
            public int getStatus() {
                return status;
            }
            public void setStatus(int status) {
                this.status = status;
            }
            public String getValue() {
                return value;
            }
            public void setValue(String value) {
                this.value = value;
            }
        }
    }
    public static void main(String[] args) {
            // TODO Auto-generated method stub
            
            //toXml
    //        String xmlStr=new PersonTest().toXml();
            
            //toBean
    //        XjdbBean per=new PersonTest().toBean();
            String xmlStr="<?xml version="1.0" encoding="UTF-8"?>"+"<data>"+
                      "  <message>"+
                      "    <status>0</status>"+
                      "    <value>处理成功</value>"+
                      "  </message>"+
                      "<xjCompares>"+
                      "    <xjCompare inputXm="张国俊" inputZjhm="420984199202015311" inputYxmc="" inputCc="" inputXllb="" inputRxrq="">"+
                      "      <wybs desc="唯一标识">40288940560cfc780156262f01a344e3</wybs>"+
                      "      <message>"+
                      "        <status>1</status>"+
                      "        <value>查询成功_无数据</value>"+
                      "      </message>"+
                      "      <yjbyrq desc="预计毕业日期">201507</yjbyrq>"+
                      "      <xllbCheckrs desc="学历类别比对结果">1</xllbCheckrs>    "+
                      "      <rxrqCheckrs desc="入学日期比对结果">1</rxrqCheckrs>"+
                      "      <yxmcCheckrs desc="院校比对结果">1</yxmcCheckrs>"+
                      "      <ccCheckrs desc="学习层次比对结果">1</ccCheckrs>    "+
                      "      <xjCheckrs desc="学籍比对结果">1</xjCheckrs>"+
                      "    </xjCompare>"+
                      "  </xjCompares>"+
                      ""+
                      ""+
                    "</data>";
            XjdbBean person=XmlUtil.toBean(xmlStr, XjdbBean.class);
            System.out.println("person=firstname=="+person.getMessage().getValue());
            System.out.println("person=firstname=="+person.getXjCompares().getXjCompare().getMessage().getStatus());
            System.out.println("0".equals(person.getXjCompares().getXjCompare().getMessage().getStatus()));
            if(0==person.getXjCompares().getXjCompare().getMessage().getStatus()){
                System.out.println("person=firstname=="+person.getXjCompares().getXjCompare().getYjbyrq());
            }
            /*System.out.println("person==Friends==name1=="+person.getFriend().getName().get(0));
            System.out.println("person==Pets==name2=="+person.getPet().getAnimalList().get(1).getName());*/
            
        }
  • 相关阅读:
    css实现一行居中显示,两行靠左显示
    杂记
    去除inline-block元素间间距的N种方法
    ps快捷键
    python3使用ltp语言云
    WEKA “Detailed Accuracy By Class”和“Confusion Matrix”含义
    分类问题的精确率和召回率 (准确率)
    修改文件所属组和用户
    linux添加新用户
    linux新建用户tab无法补全命令
  • 原文地址:https://www.cnblogs.com/sprinng/p/5712157.html
Copyright © 2020-2023  润新知