根据xml文件生成javaBean

本文介绍了如何将天猫对象转换为JavaBean,通过trang.jar将xml转换为xsd,然后使用xjc命令生成对应的JavaBean源代码,从而简化数据处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近有个跟天猫对接的事情,我们需要把天猫的对象转成JavaBean这样好处理
总共有三个步骤
1.利用trang.jar对xml进行xsd的转换
可运行命令:java -jar trang.jar test.xml test.xsd
在这里插入图片描述
trang.jar 下载地址:
https://pan.baidu.com/s/1viOVOqlVdRdzXeJ1fL7dFA?errno=0&errmsg=Auth Login Sucess&&bduss=&ssnerror=0&traceid=

test.xml文件如下:

<?xml version="1.0" encoding="utf-8"?>
<items>
    <totalResults>10</totalResults>
    <totalResultsAll>80</totalResultsAll>
    <Rows>
        <resultNum>1</resultNum>
        <storage_id>310</storage_id>
        <tid>S1905050000202</tid>
        <transaction_id>3213213</transaction_id>
        <customer_id>3213213</customer_id>
        <distributor_id>3213213</distributor_id>
        <shop_name>LU咔咔店铺</shop_name>
        <out_tid>5702264429224972</out_tid>
        <out_pay_tid>3213213</out_pay_tid>
        <voucher_id>3213213</voucher_id>
        <shopid>97</shopid>
        <serial_num>32</serial_num>
        <order_channel>直营网店</order_channel>
        <order_from>test</order_from>
        <buyer_id>316</buyer_id>
        <buyer_name>test</buyer_name>
        <type>正常订单</type>
        <status>已确认</status>
        <abnormal_status>0</abnormal_status>
        <merge_status>手动拆分</merge_status>
        <receiver_name>测试63</receiver_name>
        <receiver_mobile>13000000063</receiver_mobile>
        <phone>188989898989</phone>
        <province>上海</province>
        <city>上海市</city>
        <district>虹口区</district>
        <address>上海市 上海城区 虹口区.上海市虹口区.广粤路138号 上海市虹口高级中学</address>
        <post>32113</post>
        <email>tesset</email>
        <is_bill>0</is_bill>
        <invoice_name>name</invoice_name>
        <invoice_situation>0</invoice_situation>
        <invoice_title>323213</invoice_title>
        <invoice_type>2</invoice_type>
        <invoice_content>323</invoice_content>
        <pro_totalfee>4.4500</pro_totalfee>
        <order_totalfee>4.4500</order_totalfee>
        <reference_price_paid>4.4496</reference_price_paid>
        <invoice_fee>4.4496</invoice_fee>
        <cod_fee>323</cod_fee>
        <other_fee>3213</other_fee>
        <refund_totalfee>323</refund_totalfee>
        <discount_fee>9.6018</discount_fee>
        <discount>90</discount>
        <channel_disfee>32</channel_disfee>
        <merchant_disfee>32</merchant_disfee>
        <order_disfee>4.4496</order_disfee>
        <commission_fee>0.0000</commission_fee>
        <is_cod>1</is_cod>
        <point_pay>test</point_pay>
        <cost_point>0.00</cost_point>
        <point>tet</point>
        <superior_point>wree</superior_point>
        <royalty_fee>wre</royalty_fee>
        <external_point>ewqe</external_point>
        <express_no>322122333</express_no>
        <express>百世汇通</express>
        <express_coding>HTKY</express_coding>
        <online_express>fdsfdd</online_express>
        <sending_type>fdssf</sending_type>
        <real_income_freight>0.00</real_income_freight>
        <real_pay_freight>fdssf</real_pay_freight>
        <gross_weight>0.000</gross_weight>
        <gross_weight_freight>ewqe</gross_weight_freight>
        <net_weight_freight>0.00</net_weight_freight>
        <freight_explain>fdsf</freight_explain>
        <total_weight>fdsf</total_weight>
        <tid_net_weight>0.20</tid_net_weight>
        <tid_time>2019-05-05 10:17:24</tid_time>
        <pay_time>2019-05-05 10:17:24</pay_time>
        <get_time>2019-05-05 10:18:34</get_time>
        <order_creater>fdsfd</order_creater>
        <business_man>fdsfd</business_man>
        <payment_received_operator>fdsf</payment_received_operator>
        <payment_received_time>fdssf</payment_received_time>
        <review_orders_operator>edb_b279995</review_orders_operator>
        <review_orders_time>2019-05-05 10:20:53</review_orders_time>
        <finance_review_operator>fdsfd</finance_review_operator>
        <finance_review_time>fdssfd</finance_review_time>
        <advance_printer>fdsf</advance_printer>
        <printer>edb_b279995</printer>
        <print_time>2019-05-05 10:29:34</print_time>
        <is_print>1</is_print>
        <adv_distributer>fds</adv_distributer>
        <adv_distribut_time>fds</adv_distribut_time>
        <distributer>fdsf</distributer>
        <distribut_time>2019-05-05 10:29:34</distribut_time>
        <is_inspection>0</is_inspection>
        <inspecter>321</inspecter>
        <inspect_time>2019-05-05 10:29:34</inspect_time>
        <cancel_operator>fdsfd</cancel_operator>
        <cancel_time>2019-05-05 10:29:34</cancel_time>
        <revoke_cancel_er>fdsf</revoke_cancel_er>
        <revoke_cancel_time>2019-05-05 10:29:34</revoke_cancel_time>
        <packager>fdsf</packager>
        <pack_time>fdsf</pack_time>
        <weigh_operator>fdsfd</weigh_operator>
        <weigh_time>dsdsad</weigh_time>
        <book_delivery_time>2019-05-05 10:29:34</book_delivery_time>
        <delivery_operator>fdsfdd</delivery_operator>
        <delivery_time>2019-05-05 10:29:34</delivery_time>
        <locker>fddsf</locker>
        <lock_time>2019-05-05 10:29:34</lock_time>
        <book_file_time>2019-05-05 10:29:34</book_file_time>
        <file_operator>fdsfd</file_operator>
        <file_time>2019-05-05 10:29:34</file_time>
        <finish_time>2019-05-05 10:29:34</finish_time>
        <modity_time>2019-05-05 10:29:34</modity_time>
        <is_promotion>0</is_promotion>
        <promotion_plan>fds</promotion_plan>
        <out_promotion_detail>fdssf</out_promotion_detail>
        <good_receive_time>2019-05-05 10:29:34</good_receive_time>
        <receive_time>2019-05-05 10:29:34</receive_time>
        <verificaty_time>2019-05-05 10:29:34</verificaty_time>
        <enable_inte_sto_time>2019-05-05 10:29:34</enable_inte_sto_time>
        <enable_inte_delivery_time>2019-05-05 10:18:39</enable_inte_delivery_time>
        <alipay_id>323</alipay_id>
        <alipay_status>0</alipay_status>
        <pay_mothed>在线支付</pay_mothed>
        <pay_status>未付款</pay_status>
        <platform_status>货到付款</platform_status>
        <rate>0.0</rate>
        <currency>3213</currency>
        <delivery_status>未发货</delivery_status>
        <buyer_message>fdafdsaf</buyer_message>
        <service_remarks>订单已导入</service_remarks>
        <inner_lable>fdsfa</inner_lable>
        <distributor_mark>fdsfd</distributor_mark>
        <system_remarks>fdsf</system_remarks>
        <other_remarks>fdsfd</other_remarks>
        <message>fsdfsdf</message>
        <message_time>2019-05-05 10:18:39</message_time>
        <is_stock>0</is_stock>
        <related_orders>32132</related_orders>
        <related_orders_type>2</related_orders_type>
        <import_mark>已导入</import_mark>
        <delivery_name>fdsf</delivery_name>
        <is_new_customer>0</is_new_customer>
        <distributor_level>1</distributor_level>
        <cod_service_fee>0.00</cod_service_fee>
        <express_col_fee>4.45</express_col_fee>
        <product_num>1</product_num>
        <sku>1</sku>
        <item_num>1</item_num>
        <single_num>1</single_num>
        <flag_color>fdsf</flag_color>
        <is_flag>0</is_flag>
        <taobao_delivery_order_status>货到付款</taobao_delivery_order_status>
        <taobao_delivery_status>0</taobao_delivery_status>
        <taobao_delivery_method>0</taobao_delivery_method>
        <order_process_time>2019-05-05 10:18:39</order_process_time>
        <is_break>0</is_break>
        <breaker>fdssf</breaker>
        <break_time>fdssf</break_time>
        <break_explain>fdsf</break_explain>
        <plat_send_status>0</plat_send_status>
        <plat_type>独立网店</plat_type>
        <is_adv_sale>0</is_adv_sale>
        <provinc_code>310000</provinc_code>
        <city_code>310100</city_code>
        <area_code>310109</area_code>
        <express_code>10</express_code>
        <last_returned_time>2019-05-05 10:18:39</last_returned_time>
        <last_refund_time>2019-05-05 10:18:39</last_refund_time>
        <deliver_centre>fdssf</deliver_centre>
        <deliver_station>fdssf</deliver_station>
        <is_pre_delivery_notice>0</is_pre_delivery_notice>
        <jd_delivery_time>2019-05-05 10:18:39</jd_delivery_time>
        <Sorting_code>fds</Sorting_code>
        <cod_settlement_vouchernumber>fdssf</cod_settlement_vouchernumber>
        <three_codes>fdsfd</three_codes>
        <send_site_name>fdsf</send_site_name>
        <distributing_centre_name>fdsf</distributing_centre_name>
        <gathering_ground>fsdsf</gathering_ground>
        <total_num>80</total_num>
        <originCode>fdsfd</originCode>
        <destCode>fdss</destCode>
        <big_marker>fdssf</big_marker>
        <platform_preferential>0.00</platform_preferential>
        <updatetime>2019-05-05 10:18:39</updatetime>
        <maxrowver>fdssf</maxrowver>
        <tid_item>
            <Item>
                <storage_id>310</storage_id>
                <tid>S1905050000202</tid>
                <pro_detail_code>86593</pro_detail_code>
                <pro_name>力谱云--凤梨</pro_name>
                <specification>黄色</specification>
                <barcode>LUKAKAA0000</barcode>
                <combine_barcode>fdsfdfdfdss</combine_barcode>
                <iscancel>0</iscancel>
                <isscheduled>0</isscheduled>
                <stock_situation>0</stock_situation>
                <isbook_pro>0</isbook_pro>
                <iscombination>0</iscombination>
                <isgifts>0</isgifts>
                <gift_num>0</gift_num>
                <book_storage>10</book_storage>
                <pro_num>1</pro_num>
                <send_num>1</send_num>
                <refund_num>21</refund_num>
                <refund_renum>1</refund_renum>
                <inspection_num>1</inspection_num>
                <timeinventory>23</timeinventory>
                <cost_price>1.4423</cost_price>
                <sell_price>4.4500</sell_price>
                <average_price>23.21</average_price>
                <original_price>15.0000</original_price>
                <sys_price>2.8000</sys_price>
                <ferght>0.0000</ferght>
                <item_discountfee>6.1000</item_discountfee>
                <inspection_time>2019-05-05 10:18:39</inspection_time>
                <weight>0.200</weight>
                <shopid>2132</shopid>
                <out_tid>5702264429224972</out_tid>
                <sub_tid>219034</sub_tid>
                <out_proid>32321</out_proid>
                <out_prosku>adsadssa</out_prosku>
                <proexplain>fdsfadsf</proexplain>
                <product_name>e店宝凤梨</product_name>
                <buyer_memo>fdsfsd</buyer_memo>
                <seller_remark>dsadsd</seller_remark>
                <distributer>fdsfds</distributer>
                <distribut_time>32132</distribut_time>
                <second_barcode>332133</second_barcode>
                <product_no>LUKAKA003</product_no>
                <brand_number>5154</brand_number>
                <brand_name>LU咔咔品牌</brand_name>
                <book_inventory>82.000</book_inventory>
                <product_specification>颜色</product_specification>
                <credit_amount>4.4500</credit_amount>
                <MD5_encryption>23a48ee1-6094-4cd7-a8c2-0f24f7d1b1a8</MD5_encryption>
                <sncode>323ew</sncode>
                <store_location>THZCW</store_location>
                <pro_type>原始产品</pro_type>
            </Item>
        </tid_item>
    </Rows>
</items>

执行命令后,生成了一个test.xsd文件
在这里插入图片描述
注意:xml中的每个节点必须要有数据,要不然trang转换的时候是不知道当前数据类型的,就会做为一个对象,例如book_inventory这个节点没有数据的时候就会生成一个BookInventory对象,为了避免这种情况,对需要进行xsd转换的xml需要补全其信息

2.生成xsd文件之后可以用xjc 去生成对应的javaBean文件
执行命令:xjc test.xsd -p test.java
在这里插入图片描述
最后就能生成对应的javaBean文件了

节省很多时间

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值