The <commentGenerator> Element

The <commentGenerator> element is used to define properties of the Comment Generator. The Comment Generator is used to generate comments for the various elements generated by MyBatis Generator (MBG) (Java fields, Java methods, XML elements, etc.). The default Comment Generator adds JavaDoc comments to all generated Java elements to enable the Java merge functionality in the Eclipse plugin. Also, comments are added to each generated XML element. The purpose of the comments is also to inform users that the elements are generated and are subject to regeneration (i.e. - they shouldn't be altered). This element is an optional child element of the <context> element.

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

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 coments in the generated code. The property supports these values:
false This is the default value
When the property is false or unspecified, all generated elelments will include comments indicationg that the element is a generated element.
true When the property is true, no comments will be added to any generated element.

Warning: if you set this value to true, then all code merging will be disabled.

suppressDate This property is used to specify whether MBG will include the generation timestamp in the generated comments. The property supports these values:
false This is the default value
When the property is false or unspecified, all generated comments will include the timestamp when the element was generated.
true When the property is true, no timestamp will be added to the generated comments.

Example

This element specifies that we do not want the timestamp added to any generated comment:

<commentGenerator>
  <property name="suppressDate" value="true" />
</commentGenerator>