0

mybatis ジェネレーターのプラグインをコーディングしましたが、clientGenerated の extends プラグイン メソッドが機能しません。私を助けてください〜^_^
コードは以下にあります:


public class MapperAnnotationPlugin extends PluginAdapter {
    private final static Map<String, String> ANNOTATION_IMPORTS;
    static {
        ANNOTATION_IMPORTS = new HashMap<>();
        ANNOTATION_IMPORTS.put("@Mapper", "org.apache.ibatis.annotations.Mapper");
        ANNOTATION_IMPORTS.put("@Repository", "org.springframework.stereotype.Repository");
    }
    private List<String> annotationList;
    @Override
    public void initialized(IntrospectedTable introspectedTable) {
        super.initialized(introspectedTable);
        this.annotationList = new ArrayList<>();
        Properties properties = this.getProperties();
        boolean findMapper = false;
        for (Object key : properties.keySet()) {
            String keyStr = key.toString().trim();
            if (keyStr.startsWith("@Mapper")) {
                findMapper = true;
            }

            if (StringUtility.isTrue(properties.getProperty(key.toString()))) {
                annotationList.add(keyStr);
            }
        }
        if (!findMapper) {
            annotationList.add(0, "@Mapper");
        }
    }

    @Override
    public boolean clientGenerated(Interface interfaze, IntrospectedTable introspectedTable) {
        super.clientGenerated(interfaze, introspectedTable);
        for (String annotation : annotationList) {
            if ("@Mapper".equals(annotation)) {
                if (introspectedTable.getTargetRuntime() == IntrospectedTable.TargetRuntime.MYBATIS3) {
                    interfaze.addImportedType(new FullyQualifiedJavaType(ANNOTATION_IMPORTS.get(annotation)));
                    interfaze.addAnnotation(annotation);
                }
            } else if (Objects.nonNull(ANNOTATION_IMPORTS.get(annotation))) {
                logger.info(PluginConst.TEACHEE_PLUGIN + "添加" + annotation);
                interfaze.addImportedType(new FullyQualifiedJavaType(ANNOTATION_IMPORTS.get(annotation)));
                interfaze.addAnnotation(annotation);
            }
        }
        return true;
    }
}

2番目の方法で、デバッグでは、この方法に行かなかったので、次のステップで何ができるでしょうか

4

1 に答える 1