原创

使用idea进行文本的批量化编辑

1、背景

  • 使用idea插件gsonformat根据json生成对应的bean
  • 问题是产生了比较多的jackson注解,而且属性比较多。一个个删除效率比较低。

代码示例

package net.gzcx;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @author chen xing
 * @description TODO
 * @date 2022-07-14 8:59
 */
@NoArgsConstructor
@Data
public class A {

    @com.fasterxml.jackson.annotation.JsonProperty("action")
    private String action;
    @com.fasterxml.jackson.annotation.JsonProperty("signFlowId")
    private String signFlowId;
    @com.fasterxml.jackson.annotation.JsonProperty("signFlowTitle")
    private String signFlowTitle;
    @com.fasterxml.jackson.annotation.JsonProperty("signFlowStatus")
    private String signFlowStatus;
    @com.fasterxml.jackson.annotation.JsonProperty("transactorPsnId")
    private String transactorPsnId;
    @com.fasterxml.jackson.annotation.JsonProperty("orgId")
    private String orgId;
    @com.fasterxml.jackson.annotation.JsonProperty("viewUrl")
    private String viewUrl;
    @com.fasterxml.jackson.annotation.JsonProperty("signUrl")
    private String signUrl;
    @com.fasterxml.jackson.annotation.JsonProperty("copiers")
    private List<CopiersDTO> copiers;
    @com.fasterxml.jackson.annotation.JsonProperty("signers")
    private List<SignersDTO> signers;
    @com.fasterxml.jackson.annotation.JsonProperty("timestamp")
    private Long timestamp;

    @NoArgsConstructor
    @Data
    public static class CopiersDTO {
        @com.fasterxml.jackson.annotation.JsonProperty("copierPsnId")
        private String copierPsnId;
        @com.fasterxml.jackson.annotation.JsonProperty("copierPsnName")
        private String copierPsnName;
        @com.fasterxml.jackson.annotation.JsonProperty("copierOrgId")
        private String copierOrgId;
        @com.fasterxml.jackson.annotation.JsonProperty("copierOrgName")
        private String copierOrgName;
    }

    @NoArgsConstructor
    @Data
    public static class SignersDTO {
        @com.fasterxml.jackson.annotation.JsonProperty("signStatus")
        private String signStatus;
        @com.fasterxml.jackson.annotation.JsonProperty("orgSigner")
        private SignersDTO.OrgSignerDTO orgSigner;
        @com.fasterxml.jackson.annotation.JsonProperty("psnSigner")
        private SignersDTO.PsnSignerDTO psnSigner;

        @NoArgsConstructor
        @Data
        public static class OrgSignerDTO {
            @com.fasterxml.jackson.annotation.JsonProperty("orgId")
            private String orgId;
            @com.fasterxml.jackson.annotation.JsonProperty("orgName")
            private String orgName;
            @com.fasterxml.jackson.annotation.JsonProperty("transactor")
            private TransactorDTO transactor;

            @NoArgsConstructor
            @Data
            public static class TransactorDTO {
                @com.fasterxml.jackson.annotation.JsonProperty("psnName")
                private String psnName;
                @com.fasterxml.jackson.annotation.JsonProperty("psnId")
                private String psnId;
            }
        }

        @NoArgsConstructor
        @Data
        public static class PsnSignerDTO {
            @com.fasterxml.jackson.annotation.JsonProperty("psnName")
            private String psnName;
            @com.fasterxml.jackson.annotation.JsonProperty("psnId")
            private String psnId;
        }
    }
}

2、解决办法

  • 搜索需要统一去掉内容中独特的关键字,比如这里的JsonProperty
  • 选择工具栏中的select all occurrences
  • 选中了所有的行,进行批量化操作,移动光标不要选择字符,ctrl+x剪切整个一行。因为是批量化操作。所有其他行也统一被删了。

包含jsonproperty的示例
批量操作后代码

正文到此结束
本文目录