Java Code Examples for org.mybatis.generator.api.dom.java.Method#getParameters()

The following examples show how to use org.mybatis.generator.api.dom.java.Method#getParameters() . 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: JavaElementTools.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * clone
 * @param method
 * @return
 */
public static Method clone(Method method) {
    Method dest = new Method(method.getName());
    // 注解
    for (String javaDocLine : method.getJavaDocLines()) {
        dest.addJavaDocLine(javaDocLine);
    }
    dest.setReturnType(method.getReturnType());
    for (Parameter parameter : method.getParameters()) {
        dest.addParameter(JavaElementTools.clone(parameter));
    }
    for (FullyQualifiedJavaType exception : method.getExceptions()) {
        dest.addException(exception);
    }
    for (TypeParameter typeParameter : method.getTypeParameters()) {
        dest.addTypeParameter(typeParameter);
    }
    dest.addBodyLines(method.getBodyLines());
    dest.setConstructor(method.isConstructor());
    dest.setNative(method.isNative());
    dest.setSynchronized(method.isSynchronized());
    dest.setDefault(method.isDefault());
    dest.setFinal(method.isFinal());
    dest.setStatic(method.isStatic());
    dest.setVisibility(method.getVisibility());
    return dest;
}
 
Example 2
Source File: DGCommentGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public void addGeneralMethodComment(Method method, IntrospectedTable introspectedTable) {
    // 生成方法注释
    method.addJavaDocLine("/**");
    String method_name = method.getName();

    if ("deleteByPrimaryKey".equals(method_name)) {
        method.addJavaDocLine(" * 根据主键删除数据库的记录");
    } else if ("insert".equals(method_name)) {
        method.addJavaDocLine(" * 插入数据库记录");
    } else if ("selectByPrimaryKey".equals(method_name)) {
        method.addJavaDocLine(" * 根据主键获取一条数据库记录");
    } else if ("updateByPrimaryKey".equals(method_name)) {
        method.addJavaDocLine(" * 根据主键来更新数据库记录");
    } else if ("selectAll".equals(method_name)) {
        method.addJavaDocLine(" * 获取全部数据库记录");
    }
    method.addJavaDocLine(" *");
    List<Parameter> parameterList = method.getParameters();
    String paramterName;
    for (Parameter parameter : parameterList) {
        paramterName = parameter.getName();
        method.addJavaDocLine(" * @param " + paramterName);
    }
    // addJavadocTag(method, false);
    method.addJavaDocLine(" */");
}
 
Example 3
Source File: AbstractDAOTemplate.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the method clones.
 *
 * @param commentGenerator
 *            the comment generator
 * @param introspectedTable
 *            the introspected table
 * @return the method clones
 */
public final List<Method> getMethodClones(
        CommentGenerator commentGenerator,
        IntrospectedTable introspectedTable) {
    configure();
    List<Method> answer = new ArrayList<Method>();
    for (Method oldMethod : methods) {
        Method method = new Method();

        for (String bodyLine : oldMethod.getBodyLines()) {
            method.addBodyLine(bodyLine);
        }

        for (FullyQualifiedJavaType fqjt : oldMethod.getExceptions()) {
            method.addException(fqjt);
        }

        for (Parameter parm : oldMethod.getParameters()) {
            method.addParameter(parm);
        }

        method.setConstructor(oldMethod.isConstructor());
        method.setFinal(oldMethod.isFinal());
        method.setStatic(oldMethod.isStatic());
        method.setName(oldMethod.getName());
        method.setReturnType(oldMethod.getReturnType());
        method.setVisibility(oldMethod.getVisibility());

        commentGenerator.addGeneralMethodComment(method, introspectedTable);

        answer.add(method);
    }

    return answer;
}
 
Example 4
Source File: AbstractDAOTemplate.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
public final List<Method> getMethodClones(
        CommentGenerator commentGenerator,
        IntrospectedTable introspectedTable) {
    configure();
    List<Method> answer = new ArrayList<Method>();
    for (Method oldMethod : methods) {
        Method method = new Method();

        for (String bodyLine : oldMethod.getBodyLines()) {
            method.addBodyLine(bodyLine);
        }

        for (FullyQualifiedJavaType fqjt : oldMethod.getExceptions()) {
            method.addException(fqjt);
        }

        for (Parameter parm : oldMethod.getParameters()) {
            method.addParameter(parm);
        }

        method.setConstructor(oldMethod.isConstructor());
        method.setFinal(oldMethod.isFinal());
        method.setStatic(oldMethod.isStatic());
        method.setName(oldMethod.getName());
        method.setReturnType(oldMethod.getReturnType());
        method.setVisibility(oldMethod.getVisibility());

        commentGenerator.addGeneralMethodComment(method, introspectedTable);

        answer.add(method);
    }

    return answer;
}
 
Example 5
Source File: DG2CommentGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 4 votes vote down vote up
public void addGeneralMethodComment(Method method, IntrospectedTable introspectedTable) {
        StringBuilder sb = new StringBuilder();
        method.addJavaDocLine("/**"); //$NON-NLS-1$
//        method.addJavaDocLine(" * This method was generated by MyBatis Generator."); //$NON-NLS-1$

//        sb.append(" * This method corresponds to the database table "); //$NON-NLS-1$
        sb.append(" * ");
        if (method.isConstructor()) {
            sb.append(" 构造查询条件");
        }
        String method_name = method.getName();
        if ("setOrderByClause".equals(method_name)) {
            sb.append(" 设置排序字段");
        } else if ("setDistinct".equals(method_name)) {
            sb.append(" 设置过滤重复数据");
        } else if ("getOredCriteria".equals(method_name)) {
            sb.append(" 获取当前的查询条件实例");
        } else if ("isDistinct".equals(method_name)) {
            sb.append(" 是否过滤重复数据");
        } else if ("getOrderByClause".equals(method_name)) {
            sb.append(" 获取排序字段");
        } else if ("createCriteria".equals(method_name)) {
            sb.append(" 创建一个查询条件");
        } else if ("createCriteriaInternal".equals(method_name)) {
            sb.append(" 内部构建查询条件对象");
        } else if ("clear".equals(method_name)) {
            sb.append(" 清除查询条件");
        } else if ("countByExample".equals(method_name)) {
            sb.append(" 根据指定的条件获取数据库记录数");
        } else if ("deleteByExample".equals(method_name)) {
            sb.append(" 根据指定的条件删除数据库符合条件的记录");
        } else if ("deleteByPrimaryKey".equals(method_name)) {
            sb.append(" 根据主键删除数据库的记录");
        } else if ("insert".equals(method_name)) {
            sb.append(" 新写入数据库记录");
        } else if ("insertSelective".equals(method_name)) {
            sb.append(" 动态字段,写入数据库记录");
        } else if ("selectByExample".equals(method_name)) {
            sb.append(" 根据指定的条件查询符合条件的数据库记录");
        } else if ("selectByPrimaryKey".equals(method_name)) {
            sb.append(" 根据指定主键获取一条数据库记录");
        } else if ("updateByExampleSelective".equals(method_name)) {
            sb.append(" 动态根据指定的条件来更新符合条件的数据库记录");
        } else if ("updateByExample".equals(method_name)) {
            sb.append(" 根据指定的条件来更新符合条件的数据库记录");
        } else if ("updateByPrimaryKeySelective".equals(method_name)) {
            sb.append(" 动态字段,根据主键来更新符合条件的数据库记录");
        } else if ("updateByPrimaryKey".equals(method_name)) {
            sb.append(" 根据主键来更新符合条件的数据库记录");
        }
        sb.append(",");
        sb.append(introspectedTable.getFullyQualifiedTable());
        method.addJavaDocLine(sb.toString());

        final List<Parameter> parameterList = method.getParameters();
        if (!parameterList.isEmpty()) {
            method.addJavaDocLine(" *");
            if ("or".equals(method_name)) {
                sb.append(" 增加或者的查询条件,用于构建或者查询");
            }
        } else {
            if ("or".equals(method_name)) {
                sb.append(" 创建一个新的或者查询条件");
            }
        }
        String paramterName;
        for (Parameter parameter : parameterList) {
            sb.setLength(0);
            sb.append(" * @param "); //$NON-NLS-1$
            paramterName = parameter.getName();
            sb.append(paramterName);
            if ("orderByClause".equals(paramterName)) {
                sb.append(" 排序字段"); //$NON-NLS-1$
            } else if ("distinct".equals(paramterName)) {
                sb.append(" 是否过滤重复数据");
            } else if ("criteria".equals(paramterName)) {
                sb.append(" 过滤条件实例");
            }
            method.addJavaDocLine(sb.toString());
        }


        //        addJavadocTag(method, false);

        method.addJavaDocLine(" */"); //$NON-NLS-1$
    }