The <commentGenerator> Element
The <commentGenerator> element is used to define properties of the comment generator. The comment generator is used to generate comments and annotations for the various elements generated by MyBatis Generator (MBG) (Java fields, Java methods, Kotlin files, XML elements, etc.). There are two purposes for comments:
- Inform users that the elements are generated and are subject to regeneration (i.e. - they shouldn't be altered).
- Support the Java and XML merge functionality. The Java and XML mergers use the generated annotations to understand what elements can be deleted during merge operations.
This element is an optional child element of the <context> element.
In the runtimes that generate Java code, the comment generator will add a jakarta.annotation.Generated
annotation to generated Java elements.
Generated XML mappers will contain XML comments with the string "@mbg.generated".
In the Kotlin runtime, a simple comment is added to all generated Kotlin files.
The default implementation is org.mybatis.generator.internal.DefaultCommentGenerator.
The default implementation is designed for extensibility if you only want to modify certain behaviors.
Required Attributes
None
Optional Attributes
| Attribute | Description |
|---|---|
| type | This may be used to specify the type of the user provided Comment Generator.
The class must implement the interface org.mybatis.generator.api.CommentGenerator
and must have a public default constructor. The attribute also accepts
the special value DEFAULT in which case the default implementation will
be used (this has the same effect as not specifying the type). |
Child Elements
- <property> (0..N)
Supported Properties
This table lists the properties of the default comment generator that can be specified with the <property> child element:
| Property Name | Property Values | ||||
|---|---|---|---|---|---|
| suppressAllComments |
This property is used to specify whether MBG will include any comments or annotations in the generated code.
The property supports these values:
Warning: if you set this value to true, then Java and XML code merging will be effectively disabled. If you disable all comments, you might find the |
||||
| minimizeComments |
This property is used to specify that MBG should only add the minimum comments and annotations required to
support Java and XML merging. The property supports these values:
|
||||
| suppressDate |
This property is used to specify whether MBG will include the generation timestamp in the generated comments and
annotations. The timestamp is always formatted in ISO-8601 format (as required in the "@Generated" annotation).
The property supports these values:
|
||||
| addRemarkComments |
This property is used to specify whether MBG will include table and column remarks from the database table in the
generated comments. Remarks are added in two places: 1) in a general comment in a generated model class and 2) in
a comment on a generated field in a model class.
Warning: If either the "suppressAllComments" or "minimizeComments" options are true, this option will be ignored. |
Example
This element specifies that we do not want the timestamp added to any generated comment or annotation:
<commentGenerator> <property name="suppressDate" value="true" /> </commentGenerator>
