You don't need to read other blogs, just read this and you're done. Copying one of the other blogs is all wrong. It may be caused by the iteration of mybatis-generator, or it may be that I haven't tried it myself, which is a mistake.
I won't talk about how to use mybatis-generator. There are a lot of them on the Internet. Now I will talk about the following configuration, why the generated table is still not wrapped with `` characters on both sides of the table name.
<property name="javaFileEncoding" value="UTF-8"/> <property name="autoDelimitKeywords" value="true"/> <property name="beginningDelimiter" value="`"/> <property name="endingDelimiter" value="`"/>
If you just want to know the result, I can tell you here, just add a parameter to the <table> tag, and list the answer first.
<table tableName="ABC" domainObjectName="ABC" enableSelectByPrimaryKey="true" enableSelectByExample="true" enableUpdateByPrimaryKey="true" enableInsert="true" enableUpdateByExample="true" enableCountByExample="true" delimitIdentifiers="true"> </table>
This solves the problem, just set one more delimitIdentifiers parameter. You don't have to look here if you only take the results.
Here's why.
First let's find out where the beginningDelimiter and endingDelimiter are used. The following is where to use it.
org.mybatis.generator.api.FullyQualifiedTable#FullyQualifiedTable
The code for this method is as follows
public FullyQualifiedTable(String introspectedCatalog, String introspectedSchema, String introspectedTableName, String domainObjectName, String alias, boolean ignoreQualifiersAtRuntime, String runtimeCatalog, String runtimeSchema, String runtimeTableName, boolean delimitIdentifiers, DomainObjectRenamingRule domainObjectRenamingRule, Context context) { super(); this.introspectedCatalog = introspectedCatalog; this.introspectedSchema = introspectedSchema; this.introspectedTableName = introspectedTableName; this.ignoreQualifiersAtRuntime = ignoreQualifiersAtRuntime; this.runtimeCatalog = runtimeCatalog; this.runtimeSchema = runtimeSchema; this.runtimeTableName = runtimeTableName; this.domainObjectRenamingRule = domainObjectRenamingRule; if (stringHasValue(domainObjectName)) { int index = domainObjectName.lastIndexOf('.'); if (index == -1) { this.domainObjectName = domainObjectName; } else { this.domainObjectName = domainObjectName.substring(index + 1); this.domainObjectSubPackage = domainObjectName.substring(0, index); } } if (alias == null) { this.alias = null; } else { this.alias = alias.trim(); } beginningDelimiter = delimitIdentifiers ? context .getBeginningDelimiter() : ""; //$NON-NLS-1$ endingDelimiter = delimitIdentifiers ? context.getEndingDelimiter() : ""; //$NON-NLS-1$ }
I will not post the comments. At the end of this method, it is very clear that beginningDelimiter and endingDelimiter can be the values you set, but be sure to make delimitIdentifiers = true. Then we continue to find where delimitIdentifiers are set.
org.mybatis.generator.internal.db.DatabaseIntrospector#calculateIntrospectedTables
Here we see his code
private List<IntrospectedTable> calculateIntrospectedTables( TableConfiguration tc, Map<ActualTableName, List<IntrospectedColumn>> columns) { boolean delimitIdentifiers = tc.isDelimitIdentifiers() || stringContainsSpace(tc.getCatalog()) || stringContainsSpace(tc.getSchema()) || stringContainsSpace(tc.getTableName()); List<IntrospectedTable> answer = new ArrayList<IntrospectedTable>(); for (Map.Entry<ActualTableName, List<IntrospectedColumn>> entry : columns .entrySet()) { ActualTableName atn = entry.getKey(); FullyQualifiedTable table = new FullyQualifiedTable( stringHasValue(tc.getCatalog()) ? atn.getCatalog() : null, stringHasValue(tc.getSchema()) ? atn.getSchema() : null, atn.getTableName(), tc.getDomainObjectName(), tc.getAlias(), isTrue(tc.getProperty(PropertyRegistry.TABLE_IGNORE_QUALIFIERS_AT_RUNTIME)), tc.getProperty(PropertyRegistry.TABLE_RUNTIME_CATALOG), tc.getProperty(PropertyRegistry.TABLE_RUNTIME_SCHEMA), tc.getProperty(PropertyRegistry.TABLE_RUNTIME_TABLE_NAME), delimitIdentifiers, tc.getDomainObjectRenamingRule(), context); IntrospectedTable introspectedTable = ObjectFactory .createIntrospectedTable(tc, table, context); for (IntrospectedColumn introspectedColumn : entry.getValue()) { introspectedTable.addColumn(introspectedColumn); } calculatePrimaryKey(table, introspectedTable); enhanceIntrospectedTable(introspectedTable); answer.add(introspectedTable); } return answer; }
Here we can see the judgment rules of delimitIdentifiers.
From the results of the above combing, we can roughly think that the following four situations can make the settings of beginningDelimiter and endingDelimiter take effect.
1. Set the delimitIdentifiers attribute in the <table> tag .
2. The catalog attribute is set in the <table> tag , and there are spaces before and after or anywhere. (Don't ask me why, I don't know either..)
3. The schema attribute is set in the <table> tag , and there are spaces before and after or anywhere. (Don't ask me why, I don't know either..)
4. Set the tableName attribute in the <table> tag , and there are spaces before and after or anywhere. (Don't ask me why, I don't know either..)
above.