Java Code Examples for org.mybatis.generator.config.PluginConfiguration#getProperty()
The following examples show how to use
org.mybatis.generator.config.PluginConfiguration#getProperty() .
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: BasePlugin.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * 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); } }
Example 2
Source File: IntrospectedTableTools.java From mybatis-generator-plugin with Apache License 2.0 | 5 votes |
/** * 设置DomainObjectName和MapperName * @param introspectedTable * @param context * @param domainObjectName */ public static void setDomainObjectName(IntrospectedTable introspectedTable, Context context, String domainObjectName) throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { // 配置信息(没啥用) introspectedTable.getTableConfiguration().setDomainObjectName(domainObjectName); // FullyQualifiedTable修正 Field domainObjectNameField = FullyQualifiedTable.class.getDeclaredField("domainObjectName"); domainObjectNameField.setAccessible(true); domainObjectNameField.set(introspectedTable.getFullyQualifiedTable(), domainObjectName); // 重新修正introspectedTable属性信息 Method calculateJavaClientAttributes = IntrospectedTable.class.getDeclaredMethod("calculateJavaClientAttributes"); calculateJavaClientAttributes.setAccessible(true); calculateJavaClientAttributes.invoke(introspectedTable); Method calculateModelAttributes = IntrospectedTable.class.getDeclaredMethod("calculateModelAttributes"); calculateModelAttributes.setAccessible(true); calculateModelAttributes.invoke(introspectedTable); Method calculateXmlAttributes = IntrospectedTable.class.getDeclaredMethod("calculateXmlAttributes"); calculateXmlAttributes.setAccessible(true); calculateXmlAttributes.invoke(introspectedTable); // 注意!! 如果配置了ExampleTargetPlugin插件,要修正Example 位置 PluginConfiguration configuration = PluginTools.getPluginConfiguration(context, ExampleTargetPlugin.class); if (configuration != null && configuration.getProperty(ExampleTargetPlugin.PRO_TARGET_PACKAGE) != null) { String exampleType = introspectedTable.getExampleType(); // 修改包名 JavaModelGeneratorConfiguration javaModelGeneratorConfiguration = context.getJavaModelGeneratorConfiguration(); String targetPackage = javaModelGeneratorConfiguration.getTargetPackage(); String newExampleType = exampleType.replace(targetPackage, configuration.getProperty(ExampleTargetPlugin.PRO_TARGET_PACKAGE)); introspectedTable.setExampleType(newExampleType); } }