@@ -0,0 +1,3525 @@
+package com.zheng.common.plugin;%0A%0Aimport org.mybatis.generator.api.IntrospectedTable;%0Aimport org.mybatis.generator.api.PluginAdapter;%0Aimport org.mybatis.generator.api.dom.java.*;%0A%0Aimport java.util.List;%0Aimport java.util.Properties;%0A%0A/**%0A * Created by shuzheng on 2017/1/1.%0A */%0Apublic class SerializablePlugin extends PluginAdapter %7B%0A    private FullyQualifiedJavaType serializable = new FullyQualifiedJavaType(%22java.io.Serializable%22);%0A    private FullyQualifiedJavaType gwtSerializable = new FullyQualifiedJavaType(%22com.google.gwt.user.client.rpc.IsSerializable%22);%0A    private boolean addGWTInterface;%0A    private boolean suppressJavaInterface;%0A%0A    public SerializablePlugin() %7B%0A    %7D%0A%0A    public boolean validate(List%3CString%3E warnings) %7B%0A        return true;%0A    %7D%0A%0A    public void setProperties(Properties properties) %7B%0A        super.setProperties(properties);%0A        this.addGWTInterface = Boolean.valueOf(properties.getProperty(%22addGWTInterface%22)).booleanValue();%0A        this.suppressJavaInterface = Boolean.valueOf(properties.getProperty(%22suppressJavaInterface%22)).booleanValue();%0A    %7D%0A%0A    public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) %7B%0A        this.makeSerializable(topLevelClass, introspectedTable);%0A        return true;%0A    %7D%0A%0A    public boolean modelPrimaryKeyClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) %7B%0A        this.makeSerializable(topLevelClass, introspectedTable);%0A        return true;%0A    %7D%0A%0A    public boolean modelRecordWithBLOBsClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) %7B%0A        this.makeSerializable(topLevelClass, introspectedTable);%0A        return true;%0A    %7D%0A%0A    protected void makeSerializable(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) %7B%0A        if(this.addGWTInterface) %7B%0A            topLevelClass.addImportedType(this.gwtSerializable);%0A            topLevelClass.addSuperInterface(this.gwtSerializable);%0A        %7D%0A%0A        if(!this.suppressJavaInterface) %7B%0A            topLevelClass.addImportedType(this.serializable);%0A            topLevelClass.addSuperInterface(this.serializable);%0A            Field field = new Field();%0A            field.setFinal(true);%0A            field.setInitializationString(%221L%22);%0A            field.setName(%22serialVersionUID%22);%0A            field.setStatic(true);%0A            field.setType(new FullyQualifiedJavaType(%22long%22));%0A            field.setVisibility(JavaVisibility.PRIVATE);%0A            this.context.getCommentGenerator().addFieldComment(field, introspectedTable);%0A            topLevelClass.addField(field);%0A        %7D%0A%0A    %7D%0A%0A    /**%0A     * %E6%B7%BB%E5%8A%A0%E7%BB%99Example%E7%B1%BB%E5%BA%8F%E5%88%97%E5%8C%96%E7%9A%84%E6%96%B9%E6%B3%95%0A     * @param topLevelClass%0A     * @param introspectedTable%0A     * @return%0A     */%0A    @Override%0A    public boolean modelExampleClassGenerated(TopLevelClass topLevelClass,IntrospectedTable introspectedTable)%7B%0A        makeSerializable(topLevelClass, introspectedTable);%0A%0A        for (InnerClass innerClass : topLevelClass.getInnerClasses()) %7B%0A            if (%22GeneratedCriteria%22.equals(innerClass.getType().getShortName())) %7B%0A                innerClass.addSuperInterface(serializable);%0A            %7D%0A            if (%22Criteria%22.equals(innerClass.getType().getShortName())) %7B%0A                innerClass.addSuperInterface(serializable);%0A            %7D%0A            if (%22Criterion%22.equals(innerClass.getType().getShortName())) %7B%0A                innerClass.addSuperInterface(serializable);%0A            %7D%0A        %7D%0A%0A        return true;%0A    %7D%0A%0A%7D%0A

重写SerializablePlugin，使mybatis generator生成的Example类也支持实现序列化，支持分布式