02.25 代碼演示Mybatis-Generator 擴展自定義生成(上)

Mybatis-Generator 可自動生成Model、Dao、Mapper代碼,但其自帶生成的代碼存在以下問題:

  • 生成的註釋不是我們想要的,我們期望的是根據數據庫表、字段生成不同的註釋;
  • 分頁代碼生成缺失,每個公司的分頁方式不同,尤其是老久項目或已發佈API,不能隨意變動,那麼如何自適應分頁代碼生成;
  • Mapper.xml沒有group by相關代碼生成;
  • 重複生成代碼時,Mapper.xml並不是覆蓋原代碼;而是對內容進行了追加;
  • 序列化,mybatis-generator內置了SerializablePlugin,但僅對Model,並沒有對 Example序列化,在一些開發中是不夠的;
  • 對Service Layer代碼沒有生成。

實際上,mybatis-generator提供了PluginAdapter供我們來繼承,進行個性化的一些擴展(Plugin的相關內容是閱讀本文的前置條件)如果不熟悉的同學請自行補充,本文不對其進行相關介紹。同時,本文不可能涵蓋所有業務所需的擴展點,基本樣板已有,可參考本文代碼繼續進行擴展。

一、註釋的自定義生成


根據數據庫表或字段的COMMENT生成註釋。@Date 生成的時間可根據需要自己定義格式。

<code>package run.override;import java.util.Date;import java.util.Properties;import org.mybatis.generator.api.IntrospectedColumn;import org.mybatis.generator.api.IntrospectedTable;import org.mybatis.generator.api.dom.java.CompilationUnit;import org.mybatis.generator.api.dom.java.Field;import org.mybatis.generator.api.dom.java.InnerClass;import org.mybatis.generator.api.dom.java.InnerEnum;import org.mybatis.generator.api.dom.java.JavaElement;import org.mybatis.generator.api.dom.java.Method;import org.mybatis.generator.api.dom.java.Parameter;import org.mybatis.generator.api.dom.xml.XmlElement;import org.mybatis.generator.internal.DefaultCommentGenerator;import org.mybatis.generator.internal.util.StringUtility;/** * Comment Generator * @ClassName CommentGenerator * @Description * @author Marvis */public class CommentGenerator extends DefaultCommentGenerator {    private Properties properties;    private boolean suppressDate;    private boolean suppressAllComments;    public CommentGenerator() {        this.properties = new Properties();        this.suppressDate = false;        this.suppressAllComments = false;    }    public void addJavaFileComment(CompilationUnit compilationUnit) {                compilationUnit.addFileCommentLine("/*** copyright (c) 2019 Marvis  ***/");    }    /**     * XML file Comment     */    public void addComment(XmlElement xmlElement) {        if (this.suppressAllComments) {            return;        }    }    public void addRootComment(XmlElement rootElement) {    }    public void addConfigurationProperties(Properties properties) {        this.properties.putAll(properties);        this.suppressDate = StringUtility.isTrue(properties.getProperty("suppressDate"));        this.suppressAllComments = StringUtility.isTrue(properties.getProperty("suppressAllComments"));    }    protected void addJavadocTag(JavaElement javaElement, boolean markAsDoNotDelete) {        StringBuilder sb = new StringBuilder();        sb.append(" * ");        sb.append("@date");        String s = getDateString();        if (s != null) {            sb.append(' ');            sb.append(s);        }        javaElement.addJavaDocLine(sb.toString());    }    protected String getDateString() {        if (this.suppressDate) {            return null;        }        return new Date().toString();    }    /**     *  Comment of Example inner class(GeneratedCriteria ,Criterion)     */    public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable) {        if (this.suppressAllComments) {            return;        }        innerClass.addJavaDocLine("/**");        innerClass.addJavaDocLine(" * " + introspectedTable.getFullyQualifiedTable().getDomainObjectName()+ "

"); innerClass.addJavaDocLine(" * " + introspectedTable.getFullyQualifiedTable().toString()); addJavadocTag(innerClass, false); innerClass.addJavaDocLine(" */"); } public void addEnumComment(InnerEnum innerEnum, IntrospectedTable introspectedTable) { if (this.suppressAllComments) { return; } StringBuilder sb = new StringBuilder(); innerEnum.addJavaDocLine("/**"); innerEnum.addJavaDocLine(" * " + introspectedTable.getFullyQualifiedTable().getAlias()+ "

"); innerEnum.addJavaDocLine(" * " + introspectedTable.getFullyQualifiedTable()); innerEnum.addJavaDocLine(sb.toString()); addJavadocTag(innerEnum, false); innerEnum.addJavaDocLine(" */"); } /** * entity filed Comment */ public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) { if (this.suppressAllComments) { return; }// if(introspectedColumn.getRemarks() != null && !introspectedColumn.getRemarks().trim().equals("")) field.addJavaDocLine("/**"); field.addJavaDocLine(" * " + introspectedColumn.getRemarks()); field.addJavaDocLine(" * @author " ); field.addJavaDocLine(" * @date " + getDateString() ); field.addJavaDocLine(" * @return"); field.addJavaDocLine(" */"); } /** * Comment of EXample filed */ public void addFieldComment(Field field, IntrospectedTable introspectedTable) { if (this.suppressAllComments) { return; } field.addJavaDocLine("/**"); addJavadocTag(field, false); field.addJavaDocLine(" */"); } /** * Comment of Example method */ public void addGeneralMethodComment(Method method, IntrospectedTable introspectedTable) { if (this.suppressAllComments) { return; } } /** * * entity Getter Comment */ public void addGetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) { if (this.suppressAllComments) { return; } method.addJavaDocLine("/**"); method.addJavaDocLine(" * @return " + introspectedTable.getFullyQualifiedTable().getAlias() + " : " + introspectedColumn.getRemarks()); method.addJavaDocLine(" */"); } public void addSetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) { if (this.suppressAllComments) { return; } StringBuilder sb = new StringBuilder(); method.addJavaDocLine("/**"); Parameter parm = (Parameter) method.getParameters().get(0); sb.append(" * @param "); sb.append(parm.getName()); sb.append(" : "); sb.append(introspectedColumn.getRemarks()); method.addJavaDocLine(sb.toString()); method.addJavaDocLine(" */"); } /** * Comment of Example inner class(Criteria) */ public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable, boolean markAsDoNotDelete) { if (this.suppressAllComments) { return; } innerClass.addJavaDocLine("/**"); innerClass.addJavaDocLine(" * " + introspectedTable.getFullyQualifiedTable().getAlias()+ "

"); innerClass.addJavaDocLine(" * " + introspectedTable.getFullyQualifiedTable().toString()); addJavadocTag(innerClass, markAsDoNotDelete); innerClass.addJavaDocLine(" */"); }/<code>

Model 類註釋(表的描述): MySQL。

1)EntityCommentPlugin

<code>package run.override.model;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.Date;import java.util.List;import org.mybatis.generator.api.FullyQualifiedTable;import org.mybatis.generator.api.IntrospectedTable;import org.mybatis.generator.api.PluginAdapter;import org.mybatis.generator.api.dom.java.TopLevelClass;import org.mybatis.generator.internal.JDBCConnectionFactory;import org.mybatis.generator.internal.util.StringUtility;/** * Comment of Entity,only support MySQL * @ClassName CommentPlugin * @Description * @author Marvis */public class EntityCommentPlugin extends PluginAdapter {            @Override    public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {        addModelClassComment(topLevelClass, introspectedTable);        return super.modelBaseRecordClassGenerated(topLevelClass, introspectedTable);    }    @Override    public boolean modelRecordWithBLOBsClassGenerated(TopLevelClass topLevelClass,            IntrospectedTable introspectedTable) {        addModelClassComment(topLevelClass, introspectedTable);        return super.modelRecordWithBLOBsClassGenerated(topLevelClass, introspectedTable);    }    protected void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {        FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();        String tableComment = getTableComment(table);        topLevelClass.addJavaDocLine("/**");        if(StringUtility.stringHasValue(tableComment))            topLevelClass.addJavaDocLine(" * " + tableComment + "

"); topLevelClass.addJavaDocLine(" * " + table.toString() + "

"); topLevelClass.addJavaDocLine(" * @date " + new Date().toString()); topLevelClass.addJavaDocLine(" *"); topLevelClass.addJavaDocLine(" */"); } /** * @author Marvis * @date Jul 13, 2017 4:39:52 PM * @param table */ private String getTableComment(FullyQualifiedTable table) { String tableComment = ""; Connection connection = null; Statement statement = null; ResultSet rs = null; try { JDBCConnectionFactory jdbc = new JDBCConnectionFactory(context.getJdbcConnectionConfiguration()); connection = jdbc.getConnection(); statement = connection.createStatement(); rs = statement.executeQuery("SHOW CREATE TABLE " + table.getIntrospectedTableName()); if (rs != null && rs.next()) { String createDDL = rs.getString(2); int index = createDDL.indexOf("COMMENT='"); if (index < 0) { tableComment = ""; } else { tableComment = createDDL.substring(index + 9); tableComment = tableComment.substring(0, tableComment.length() - 1); } } } catch (SQLException e) { } finally { closeConnection(connection, statement, rs); } return tableComment; } /** * * @author Marvis * @date Jul 13, 2017 4:45:26 PM * @param connection * @param statement * @param rs */ private void closeConnection(Connection connection, Statement statement, ResultSet rs) { try { if (null != rs) rs.close(); } catch (SQLException e) { e.printStackTrace(); } finally { try { if (statement != null) statement.close(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (connection != null) connection.close(); } catch (SQLException e) { e.printStackTrace(); } } } } /** * This plugin is always valid - no properties are required */ @Override public boolean validate(List<string> warnings) { return true; }}/<string>/<code>


二、分頁和分組代碼生成


這裡,我對Dao Model進行了通用方法的抽取,建立通用基類。同時,對其進行了一些擴展,增加分頁和分組。

先對基類進行介紹。

1)BaseMapper

<code>package cn.xxx.core.base.dao;import java.util.List;import org.apache.ibatis.annotations.Param;public interface BaseMapper {        long countByExample(Example example);    int deleteByExample(Example example);    int deleteByPrimaryKey(ID id);    int insert(T record);    int insertSelective(T record);    List selectByExample(Example example);    T selectByPrimaryKey(ID id);    int updateByExampleSelective(@Param("record") T record, @Param("example") Example example);    int updateByExample(@Param("record") T record, @Param("example") Example example);    int updateByPrimaryKeySelective(T record);    int updateByPrimaryKey(T record);} 
/<code>

2)BaseExample

<code>package cn.xxx.core.base.model;/** * BaseExample 基類 * @ClassName BaseExample * @Description 增加分頁參數 * @author Marvis * @date Jul 31, 2017 11:26:53 AM */public abstract class BaseExample {    protected PageInfo pageInfo;    protected String groupByClause;    public PageInfo getPageInfo() {        return pageInfo;    }    public void setPageInfo(PageInfo pageInfo) {        this.pageInfo = pageInfo;    }    public String getGroupByClause() {        return groupByClause;    }    public void setGroupByClause(String groupByClause) {        this.groupByClause = groupByClause;    }    }/<code>

3)PageInfo

<code>package cn.xxx.core.base.model;import com.fasterxml.jackson.annotation.JsonIgnore;/** * 分頁查詢參數類 * * @author * */public class PageInfo {    public static final int Default_PageSize = 20;    // 當前頁碼    protected int currentPage = 1;    // 總頁數    protected int totalPage;    // 總記錄數    protected int totalCount;    // 每頁條數    protected int pageSize = Default_PageSize;    // 開始    protected int pageBegin = 0;    // 結束    protected int pageEnd = 20;    /**     * bean起始座標(不包含)     */    private Integer pageBeginId = null;    public static final String PageQuery_classname = "pageInfo";    /**     * 將分佈參數傳入處理,最終計算出當前頁碼PageQuery_currPage,開始座標PageQuery_star,     * 結束座標PageQuery_end,總頁數PageQuery_Psize     * 

* 頁數從1開始計數 * * @param totalCount * 記錄總數 * @param pageSize * 每頁顯示個數 * @param currentPage * 當前頁碼 */ public void setPageParams(int totalCount, int pageSize, int currentPage) { this.totalPage = pageSize == 0 ? 1 : (int) Math.ceil((double) totalCount / (double) pageSize); this.totalCount = totalCount; this.pageSize = pageSize; this.currentPage = currentPage; float Psize_l = totalCount / (float) (this.pageSize); if (currentPage < 2) { currentPage = 1; pageBegin = 0; } else if (currentPage > Psize_l) { if (Psize_l == 0) { currentPage = 1; } else { currentPage = (int) Math.ceil(Psize_l); } pageBegin = (currentPage - 1) * this.pageSize; } else { pageBegin = (currentPage - 1) * this.pageSize; } pageSize = (int) Math.ceil(Psize_l); this.pageEnd = currentPage * this.pageSize; if (this.currentPage <= 0 || this.currentPage > this.totalPage) this.pageSize = 0; } /** * 將分佈參數傳入處理,最終計算出當前頁碼PageQuery_currPage,開始座標PageQuery_star, * 結束座標PageQuery_end,總頁數PageQuery_Psize * * @param infoCount * 記錄總數 */ public void setPageParams(int totalCount) { this.setPageParams(totalCount, this.pageSize, this.currentPage); } @Override public String toString() { return "PageInfo [currentPage=" + currentPage + ", totalPage=" + totalPage + ", totalCount=" + totalCount + ", pageSize=" + pageSize + ", pageBegin=" + pageBegin + ", pageEnd=" + pageEnd + ", pageBeginId=" + pageBeginId + "]"; } public int getCurrentPage() { return currentPage; } public int getTotalPage() { return totalPage; } public int getTotalCount() { return totalCount; } /** * 每頁顯示個數 */ public int getPageSize() { return pageSize; } @JsonIgnore public int getPageBegin() { return pageBegin; } @JsonIgnore public int getPageEnd() { return pageEnd; } /** * bean起始id(不包含) */ @JsonIgnore public Integer getPageBeginId() { return pageBeginId; } /** * 請求頁 */ public void setCurrentPage(int currentPage) { this.currentPage = currentPage; } /** * 每頁顯示個數 */ public void setPageSize(int pageSize) { this.pageSize = pageSize; }}/<code>

4)PaginationPlugin

分頁擴展。並且Example繼承BaseExample。

<code>package run.override.pagination;import org.mybatis.generator.api.IntrospectedTable;import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;import org.mybatis.generator.api.dom.java.TopLevelClass;import org.mybatis.generator.api.dom.xml.Attribute;import org.mybatis.generator.api.dom.xml.TextElement;import org.mybatis.generator.api.dom.xml.XmlElement;import run.override.mapper.SqlMapIsMergeablePlugin;import run.override.proxyFactory.FullyQualifiedJavaTypeProxyFactory;public class PaginationPlugin extends SqlMapIsMergeablePlugin {    @Override    public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {        FullyQualifiedJavaType baseExampleType = FullyQualifiedJavaTypeProxyFactory.getBaseExampleInstance();        topLevelClass.setSuperClass(baseExampleType);                topLevelClass.addImportedType(baseExampleType);        return super.modelExampleClassGenerated(topLevelClass, introspectedTable);    }        @Override    public boolean sqlMapSelectByExampleWithBLOBsElementGenerated(XmlElement element,            IntrospectedTable introspectedTable) {        XmlElement isNotNullElement1 = new XmlElement("if");        isNotNullElement1.addAttribute(new Attribute("test", "groupByClause != null"));        isNotNullElement1.addElement(new TextElement("group by ${groupByClause}"));        element.addElement(5, isNotNullElement1);        XmlElement isNotNullElement = new XmlElement("if");        isNotNullElement.addAttribute(new Attribute("test", "pageInfo != null"));        isNotNullElement.addElement(new TextElement("limit #{pageInfo.pageBegin} , #{pageInfo.pageSize}"));        element.addElement(isNotNullElement);        return super.sqlMapUpdateByExampleWithBLOBsElementGenerated(element, introspectedTable);    }    @Override    public boolean sqlMapSelectByExampleWithoutBLOBsElementGenerated(XmlElement element,            IntrospectedTable introspectedTable) {        XmlElement isNotNullElement1 = new XmlElement("if");        isNotNullElement1.addAttribute(new Attribute("test", "groupByClause != null"));        isNotNullElement1.addElement(new TextElement("group by ${groupByClause}"));        element.addElement(5, isNotNullElement1);        XmlElement isNotNullElement = new XmlElement("if");        isNotNullElement.addAttribute(new Attribute("test", "pageInfo != null"));        isNotNullElement.addElement(new TextElement("limit #{pageInfo.pageBegin} , #{pageInfo.pageSize}"));        element.addElement(isNotNullElement);        return super.sqlMapUpdateByExampleWithoutBLOBsElementGenerated(element, introspectedTable);    }    @Override    public boolean sqlMapCountByExampleElementGenerated(XmlElement element, IntrospectedTable introspectedTable) {        XmlElement answer = new XmlElement("select");        String fqjt = introspectedTable.getExampleType();        answer.addAttribute(new Attribute("id", introspectedTable.getCountByExampleStatementId()));        answer.addAttribute(new Attribute("parameterType", fqjt));        answer.addAttribute(new Attribute("resultType", "java.lang.Integer"));        this.context.getCommentGenerator().addComment(answer);        StringBuilder sb = new StringBuilder();        sb.append("select count(1) from ");        sb.append(introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime());        XmlElement ifElement = new XmlElement("if");        ifElement.addAttribute(new Attribute("test", "_parameter != null"));        XmlElement includeElement = new XmlElement("include");        includeElement.addAttribute(new Attribute("refid", introspectedTable.getExampleWhereClauseId()));        ifElement.addElement(includeElement);        element.getElements().clear();        element.getElements().add(new TextElement(sb.toString()));        element.getElements().add(ifElement);        return super.sqlMapUpdateByExampleWithoutBLOBsElementGenerated(element, introspectedTable);    }}/<code>

5)FullyQualifiedJavaTypeProxyFactory

<code>package run.override.proxyFactory;import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;public class FullyQualifiedJavaTypeProxyFactory  extends FullyQualifiedJavaType{        private static FullyQualifiedJavaType pageInfoInstance = new FullyQualifiedJavaType("cn.xxx.core.base.model.PageInfo");    private static FullyQualifiedJavaType baseExampleInstance = new FullyQualifiedJavaType("cn.xxx.core.base.model.BaseExample");    private static FullyQualifiedJavaType baseMapperInstance = new FullyQualifiedJavaType("cn.xxx.core.base.dao.BaseMapper");    private static FullyQualifiedJavaType baseServiceInstance = new FullyQualifiedJavaType("cn.xxx.core.base.service.BaseService");    private static FullyQualifiedJavaType baseServiceImplInstance = new FullyQualifiedJavaType("cn.xxx.core.base.service.impl.BaseServiceImpl");        public FullyQualifiedJavaTypeProxyFactory(String fullTypeSpecification) {        super(fullTypeSpecification);    }        public static final FullyQualifiedJavaType getPageInfoInstanceInstance() {        return pageInfoInstance;    }    public static final FullyQualifiedJavaType getBaseExampleInstance() {                return baseExampleInstance;    }        public static final FullyQualifiedJavaType getBaseMapperInstance() {                return baseMapperInstance;    }    public static final FullyQualifiedJavaType getBaseServiceInstance() {                return baseServiceInstance;    }    public static final FullyQualifiedJavaType getBaseServiceImplInstance() {                return baseServiceImplInstance;    }}/<code>


三、Dao生成代碼簡化


1)ClientDaoPlugin

<code>package run.override.dao;import java.util.Arrays;import java.util.List;import java.util.stream.Collectors;import org.mybatis.generator.api.IntrospectedTable;import org.mybatis.generator.api.JavaTypeResolver;import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;import org.mybatis.generator.api.dom.java.Interface;import org.mybatis.generator.api.dom.java.Method;import org.mybatis.generator.api.dom.java.TopLevelClass;import org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl;import run.override.model.EntityCommentPlugin;import run.override.proxyFactory.FullyQualifiedJavaTypeProxyFactory;/** * javaClient("XMLMAPPER") extended * * @ClassName ClientDaoPlugin * @Description Mapper.java * @author Marvis */public class ClientDaoPlugin extends EntityCommentPlugin {    @Override    public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass,            IntrospectedTable introspectedTable) {        JavaTypeResolver javaTypeResolver = new JavaTypeResolverDefaultImpl();        FullyQualifiedJavaType calculateJavaType = javaTypeResolver                .calculateJavaType(introspectedTable.getPrimaryKeyColumns().get(0));        FullyQualifiedJavaType superInterfaceType = new FullyQualifiedJavaType(                new StringBuilder("BaseMapper")                    .toString()                );        FullyQualifiedJavaType baseMapperInstance = FullyQualifiedJavaTypeProxyFactory.getBaseMapperInstance();        interfaze.addSuperInterface(superInterfaceType);        interfaze.addImportedType(baseMapperInstance);        List<method> changeMethods = interfaze.getMethods().stream()                .filter(method -> method.getName().endsWith("WithBLOBs")                        || method.getReturnType().toString().endsWith("WithBLOBs")                        || Arrays.toString(method.getParameters().toArray()).contains("WithBLOBs"))                .collect(Collectors.toList());        interfaze.getMethods().retainAll(changeMethods);        if (changeMethods.isEmpty())            interfaze.getImportedTypes().removeIf(javaType -> javaType.getFullyQualifiedName().equals("java.util.List")                    || javaType.getFullyQualifiedName().equals("org.apache.ibatis.annotations.Param"));        return super.clientGenerated(interfaze, topLevelClass, introspectedTable);    }}/<method>/<code>


四、修正


重複生成時Mapper.xml不是覆蓋原代碼,而是對內容進行了追加。

1)SqlMapIsMergeablePlugin

<code>package run.override.mapper;import org.mybatis.generator.api.GeneratedXmlFile;import org.mybatis.generator.api.IntrospectedTable;import run.override.dao.ClientDaoPlugin;public class SqlMapIsMergeablePlugin extends ClientDaoPlugin {    @Override    public boolean sqlMapGenerated(GeneratedXmlFile sqlMap, IntrospectedTable introspectedTable) {        //重新生成代碼,xml內容覆蓋        sqlMap.setMergeable(false);        return super.sqlMapGenerated(sqlMap, introspectedTable);    }}/<code>


五、序列化自定義擴展


增加Example的序列化,並增加@SuppressWarnings("serial")註解。

1)SerializablePlugin

<code>package run.override;import java.util.List;import java.util.Properties;import org.mybatis.generator.api.IntrospectedTable;import org.mybatis.generator.api.PluginAdapter;import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;import org.mybatis.generator.api.dom.java.TopLevelClass;public class SerializablePlugin extends PluginAdapter {    private FullyQualifiedJavaType serializable;    private FullyQualifiedJavaType gwtSerializable;    private boolean addGWTInterface;    private boolean suppressJavaInterface;    public SerializablePlugin() {        this.serializable = new FullyQualifiedJavaType("java.io.Serializable");        this.gwtSerializable = new FullyQualifiedJavaType("com.google.gwt.user.client.rpc.IsSerializable");    }    @Override    public void setProperties(Properties properties) {        super.setProperties(properties);        this.addGWTInterface = Boolean.valueOf(properties.getProperty("addGWTInterface")).booleanValue();        this.suppressJavaInterface = Boolean.valueOf(properties.getProperty("suppressJavaInterface")).booleanValue();    }    @Override    public boolean modelBaseRecordClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {        makeSerializable(topLevelClass, introspectedTable);        return true;    }    @Override    public boolean modelPrimaryKeyClassGenerated(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {        makeSerializable(topLevelClass, introspectedTable);        return true;    }    @Override    public boolean modelRecordWithBLOBsClassGenerated(TopLevelClass topLevelClass,            IntrospectedTable introspectedTable) {        makeSerializable(topLevelClass, introspectedTable);        return true;    }        @Override    public boolean modelExampleClassGenerated(TopLevelClass topLevelClass,IntrospectedTable introspectedTable){        makeSerializable(topLevelClass, introspectedTable);        return true;    }    protected void makeSerializable(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {        if (this.addGWTInterface) {            topLevelClass.addImportedType(this.gwtSerializable);            topLevelClass.addSuperInterface(this.gwtSerializable);        }        if (!(this.suppressJavaInterface)) {            topLevelClass.addImportedType(this.serializable);            topLevelClass.addSuperInterface(this.serializable);            topLevelClass.addAnnotation("@SuppressWarnings(\"serial\")");                    }    }        /**     * This plugin is always valid - no properties are required     */    @Override    public boolean validate(List<string> warnings) {        return true;    }}/<string>/<code>


分享到:


相關文章: