python给json 转实体类加注释的代码实现

1 通过 GsonFormatPlus 生成的实体类

package com.zcl;

import java.util.List;

public class Test{

    /**
     * org_code
     */
    private String org_code;
    /**
     * code
     */
    private String code;
    /**
     * name
     */
    private NameDTO name;
    /**
     * vendorextends
     */
    private VendorextendsDTO vendorextends;
    /**
     * taxPayingCategories
     */
    private String taxPayingCategories;
    /**
     * vendorclass
     */
    private String vendorclass;
    /**
     * country
     */
    private String country;
    /**
     * id
     */
    private String id;
    /**
     * _status
     */
    private String _status;
    /**
     * vendorOrgs
     */
    private List<VendorOrgsDTO> vendorOrgs;

    public String getOrg_code() {
        return org_code;
    }

    public void setOrg_code(String org_code) {
        this.org_code = org_code;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public NameDTO getName() {
        return name;
    }

    public void setName(NameDTO name) {
        this.name = name;
    }

    public VendorextendsDTO getVendorextends() {
        return vendorextends;
    }

    public void setVendorextends(VendorextendsDTO vendorextends) {
        this.vendorextends = vendorextends;
    }

    public String getTaxPayingCategories() {
        return taxPayingCategories;
    }

    public void setTaxPayingCategories(String taxPayingCategories) {
        this.taxPayingCategories = taxPayingCategories;
    }

    public String getVendorclass() {
        return vendorclass;
    }

    public void setVendorclass(String vendorclass) {
        this.vendorclass = vendorclass;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String get_status() {
        return _status;
    }

    public void set_status(String _status) {
        this._status = _status;
    }

    public List<VendorOrgsDTO> getVendorOrgs() {
        return vendorOrgs;
    }

    public void setVendorOrgs(List<VendorOrgsDTO> vendorOrgs) {
        this.vendorOrgs = vendorOrgs;
    }

    public static class NameDTO {
        /**
         * zh_CN
         */
        private String zh_CN;

        public String getZh_CN() {
            return zh_CN;
        }

        public void setZh_CN(String zh_CN) {
            this.zh_CN = zh_CN;
        }
    }

    public static class VendorextendsDTO {
        /**
         * _status
         */
        private String _status;
        /**
         * simplename
         */
        private SimplenameDTO simplename;
        /**
         * helpcode
         */
        private String helpcode;

        public String get_status() {
            return _status;
        }

        public void set_status(String _status) {
            this._status = _status;
        }

        public SimplenameDTO getSimplename() {
            return simplename;
        }

        public void setSimplename(SimplenameDTO simplename) {
            this.simplename = simplename;
        }

        public String getHelpcode() {
            return helpcode;
        }

        public void setHelpcode(String helpcode) {
            this.helpcode = helpcode;
        }

        public static class SimplenameDTO {
            /**
             * zh_CN
             */
            private String zh_CN;

            public String getZh_CN() {
                return zh_CN;
            }

            public void setZh_CN(String zh_CN) {
                this.zh_CN = zh_CN;
            }
        }
    }

    public static class VendorOrgsDTO {
        /**
         * id
         */
        private String id;
        /**
         * org_code
         */
        private String org_code;
        /**
         * _status
         */
        private String _status;

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getOrg_code() {
            return org_code;
        }

        public void setOrg_code(String org_code) {
            this.org_code = org_code;
        }

        public String get_status() {
            return _status;
        }

        public void set_status(String _status) {
            this._status = _status;
        }
    }
}

2 加注释

#chinese.txt
org_code	管理组织ID
code	供应商编码
name	供应商名称
 zh_CN	中文
vendorclass	所属分类ID
vendorclass_code	所属分类编码
def txt_to_dict():
    # 读取txt文件内容
    with open('chinese.txt','r',encoding='utf-8') as f:
        lines = f.readlines()
    chinese = {}
    for line in lines:
        kv = line.split()
        chinese[kv[0]]=kv[1]
    return chinese
def  read_java(chinese):
    with open('entity.java','r') as f:
        content = f.read()
    for key in chinese:
        english = "* "+key
        chinese_word = "* "+chinese[key]
        # 替换属性注释
        content = content.replace(english, str(chinese_word))
    print(content)
    with open('entity2.java','w',encoding="utf-8") as w:
        w.write(content)
def main():
    chinese = txt_to_dict();
    read_java(chinese);
if __name__ == '__main__':
    main();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值