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
- <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 in the
generated code.
The property supports these values:
Warning: if you set this value to true, then all code merging will be disabled. If you disable all comments, you might find the |
||||
suppressDate |
This property is used to specify whether MBG will include the generation
timestamp in the generated comments.
The property supports these values:
|
||||
addRemarkComments |
This property is used to specify whether MBG will include table and column
remarks from db table in the generated comments.
The property supports these values:
Warning: If suppressAllComments option is true, this option will be ignored. |
||||
dateFormat | A date format string to use when writing the date into the generated comment. This string
will be used to construct a java.text.SimpleDateFormat object. Any
valid format string for that object can be specified here. By default, the date string
will be from the toString() method on java.util.Date .
Since 1.3.4 Warning: If the suppressAllComments option is true, this option will be ignored. Warning: If the suppressDate option is true, this option will be ignored. |
||||
useLegacyGeneratedAnnotation |
Specifies whether to use an annotation from the deprecated "javax" namespace. In JDK 9+ it is recommended
to use the "jakarta" namespace instead. The property supports these values:
|
Example
This element specifies that we do not want the timestamp added to any generated comment:
<commentGenerator> <property name="suppressDate" value="true" /> </commentGenerator>