The <columnRenamingRule> Element

MyBatis Generator (MBG) uses the <columnRenamingRule> element to rename database columns before calculating the corresponding property name in an introspected table. This is useful when all columns in a table have a common prefix that should be removed before calculating the property name. For example, suppose a table contains the following columns:

  • CUST_BUSINESS_NAME
  • CUST_STREET_ADDRESS
  • CUST_CITY
  • CUST_STATE

It might be annoying to have the generated properties all containing the CUST prefix. The prefix can be removed by specifying a renaming rule like this:

<columnRenamingRule searchString="^CUST_" replaceString="" />

Note that, internally, MBG uses the java.util.regex.Matcher.replaceAll method for this function. See the documentation for that method and class for examples of the regular expression language used in Java.

This element will be ignored for any column where a <columnOverride> element matches a column - the <columnOverride> will take precedence over the renaming rule.

If specified, the renaming rule in this element will rename the column before the property name is calculated. The calculated property name may be different depending on the value of the "useActualColumnNames" property on the corresponding <table> element. The following table shows the different values that will result if the column renaming rule shown above is applied to the field set shown above:

Column Name Property if useActualColumnNames="true" Property if useActualColumnNames="false"
CUST_BUSINESS_NAME BUSINESS_NAME businessName
CUST_STREET_ADDRESS STREET_ADDRESS streetAddress
CUST_CITY CITY city
CUST_STATE STATE state

This element is an optional child element of the <table> element.

Required Attributes

Attribute Description
searchString This is a regular expression that defines the substring to be replaced.

Optional Attributes

Attribute Description
replaceString This is a string to be substituted for every occurrence of the search string. If not specified, the empty string is used.

Child Elements

None