ts2

java

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
  <context id="xxx_pj">
    <plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
    <plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin">
      <property name="searchString" value="Example"/>
      <property name="replaceString" value="Criteria"/>
    </plugin>
    <plugin type="org.mybatis.generator.plugins.RowBoundsPlugin" />
    <plugin type="xxx.plugin.BeanClassAndMapperClassNamePlugin" />
     <jdbcConnection connectionURL="jdbc:postgresql://localhost:5432/iap_db" driverClass="org.postgresql.Driver" password="imart" userId="imart" />
    <javaModelGenerator targetPackage="xxx.domain.entity" targetProject="xxx_pj/src/main/generated" />
    <sqlMapGenerator targetPackage="xxx.domain.repository" targetProject="xxx_pj/src/main/generated" />
    <javaClientGenerator targetPackage="xxx.domain.repository" targetProject="xxx_pj/src/main/generated" type="XMLMAPPER" />

<!--     <table schema="public" tableName="%t_test_order%"
     <table schema="public" tableName="%t_xx%"
 -->
 
     <table schema="public" tableName="%t_xx%"
         modelType="flat"> 
    </table>
  </context>
</generatorConfiguration>



public class BeanClassAndMapperClassNamePlugin extends PluginAdapter {

  /*
   * (非 Javadoc)
   * 
   * @see org.mybatis.generator.api.PluginAdapter#initialized(org.mybatis.generator.api.
   * IntrospectedTable)
   */
  @Override
  public void initialized(IntrospectedTable introspectedTable) {
    super.initialized(introspectedTable);

    String tableName = introspectedTable.getBaseRecordType();
    introspectedTable.setBaseRecordType(tableName + "Entity");

    String mapperName = introspectedTable.getMyBatis3JavaMapperType();
    introspectedTable.setMyBatis3JavaMapperType(mapperName.replaceAll("Mapper$", "RepositoryGen"));

    String repositoryFilename = introspectedTable.getMyBatis3XmlMapperFileName();
    introspectedTable
        .setMyBatis3XmlMapperFileName(repositoryFilename.replaceAll("Mapper", "RepositoryGen"));

    String updateWhereId = introspectedTable.getMyBatis3UpdateByExampleWhereClauseId();
    introspectedTable.setMyBatis3UpdateByExampleWhereClauseId(renameExample(updateWhereId));

    String whereId = introspectedTable.getExampleWhereClauseId();
    introspectedTable.setExampleWhereClauseId(renameExample(whereId));

    String countStatementId = introspectedTable.getCountByExampleStatementId();
    introspectedTable.setCountByExampleStatementId(renameExample(countStatementId));

    String deleteStatementId = introspectedTable.getDeleteByExampleStatementId();
    introspectedTable.setDeleteByExampleStatementId(renameExample(deleteStatementId));

    String selectBy = introspectedTable.getSelectByExampleStatementId();
    introspectedTable.setSelectByExampleStatementId(renameExample(selectBy));

    String updateBySel = introspectedTable.getUpdateByExampleSelectiveStatementId();
    introspectedTable.setUpdateByExampleSelectiveStatementId(renameExample(updateBySel));

    String updateByBean = introspectedTable.getUpdateByExampleStatementId();
    introspectedTable.setUpdateByExampleStatementId(renameExample(updateByBean));

  }

  /*
   * (非 Javadoc)
   * 
   * @see org.mybatis.generator.api.Plugin#validate(java.util.List)
   */
  @Override
  public boolean validate(List<String> arg0) {
    return true;
  }

  /**
   * リネーム(Example→Criteria)
   * 
   * @param str 変更前
   * @return
   */
  private String renameExample(String str) {
    String searchString = "Example";
    String replaceString = "Criteria";

    Pattern pattern = Pattern.compile(searchString);
    Matcher matcher = pattern.matcher(str);
    return matcher.replaceAll(replaceString);
  }
}