Java Code Examples for org.mybatis.generator.config.Context#getCommentGenerator()

The following examples show how to use org.mybatis.generator.config.Context#getCommentGenerator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MethodGeneratorTool.java    From hui-mybatis-generator-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * 默认的批量新增/更新方法构造器.
 *
 * @param interfaze         the interfaze
 * @param introspectedTable the introspected table
 * @param context           the context
 * @author HuWeihui
 * @since hui_project v1
 */
public static void defaultBatchInsertOrUpdateMethodGen(Integer type ,Interface interfaze,IntrospectedTable introspectedTable, Context context){
    Set<FullyQualifiedJavaType> importedTypes = MethodGeneratorTool.importedBaseTypesGenerator(introspectedTable);

    //List<Entity>
    FullyQualifiedJavaType listParameterType = FullyQualifiedJavaType.getNewListInstance();
    listParameterType.addTypeArgument(introspectedTable.getRules().calculateAllFieldsClass());

    String methodName = BATCH_INSERT;
    //1.batchInsert
    if (type.equals(UPDATE)){
        methodName = BATCH_UPDATE;
    }
    Method insertMethod = MethodGeneratorTool.methodGenerator(methodName,
            JavaVisibility.DEFAULT,
            FullyQualifiedJavaType.getIntInstance(),
            new Parameter(listParameterType, PARAMETER_NAME, "@Param(\"" + PARAMETER_NAME + "\")"));

    CommentGenerator commentGenerator = context.getCommentGenerator();
    commentGenerator.addGeneralMethodComment(insertMethod, introspectedTable);

    interfaze.addImportedTypes(importedTypes);
    interfaze.addMethod(insertMethod);
}
 
Example 2
Source File: BasePlugin.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Set the context under which this plugin is running.
 * @param context the new context
 */
@Override
public void setContext(Context context) {
    super.setContext(context);

    // 添加插件
    HookAggregator.getInstance().setContext(context);

    // 配置插件使用的模板引擎
    PluginConfiguration cfg = PluginTools.getPluginConfiguration(context, CommentPlugin.class);

    if (cfg == null || cfg.getProperty(CommentPlugin.PRO_TEMPLATE) == null) {
        commentGenerator = context.getCommentGenerator();
    } else {
        TemplateCommentGenerator templateCommentGenerator = new TemplateCommentGenerator(context, cfg.getProperty(CommentPlugin.PRO_TEMPLATE));

        // ITFSW 插件使用的注释生成器
        commentGenerator = templateCommentGenerator;

        // 修正系统插件
        try {
            // 先执行一次生成CommentGenerator操作,然后再替换
            context.getCommentGenerator();

            BeanUtils.setProperty(context, "commentGenerator", templateCommentGenerator);
        } catch (Exception e) {
            logger.error("反射异常", e);
        }
    }

    // mybatis版本
    if (StringUtility.stringHasValue(context.getProperty(PRO_MYBATIS_VERSION))) {
        this.mybatisVersion = context.getProperty(PRO_MYBATIS_VERSION);
    }
}