mybatis-generator-plugin icon indicating copy to clipboard operation
mybatis-generator-plugin copied to clipboard

OptimisticLockerPlugin does not support tables that have multiple primary keys

Open mrk-911 opened this issue 4 years ago • 0 comments

When generating mapper for tables that have multiple primary keys and have version column, the parameter of deleteWithVersionByPrimaryKey() method contains only the first primary key.

    /**
     * 替换主键 方法
     * @param introspectedTable
     * @param method
     * @param interfaze
     * @param methodName
     * @return
     */
    private Method replaceDeletePrimaryKeyMethod(IntrospectedTable introspectedTable, Method method, Interface interfaze, String methodName) {
        Method withVersionMethod = new Method(method);

        // 替换方法名
        withVersionMethod.setName(methodName);
        FormatTools.replaceGeneralMethodComment(commentGenerator, withVersionMethod, introspectedTable);

        Parameter versionParam = new Parameter(this.versionColumn.getFullyQualifiedJavaType(), "version", "@Param(\"version\")");
        Parameter keyParam = new Parameter(method.getParameters().get(0).getType(), method.getParameters().get(0).getName(), "@Param(\"key\")");

        withVersionMethod.getParameters().clear();
        withVersionMethod.addParameter(versionParam);
        withVersionMethod.addParameter(keyParam);

        return withVersionMethod;
    }

mrk-911 avatar Jun 10 '21 07:06 mrk-911