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

The following examples show how to use org.mybatis.generator.api.dom.java.Method#setName() . 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: AbstractDAOTemplate.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the constructor clone.
 *
 * @param commentGenerator
 *            the comment generator
 * @param type
 *            the type
 * @param introspectedTable
 *            the introspected table
 * @return the constructor clone
 */
public final Method getConstructorClone(CommentGenerator commentGenerator,
        FullyQualifiedJavaType type, IntrospectedTable introspectedTable) {
    configure();
    Method answer = new Method();
    answer.setConstructor(true);
    answer.setName(type.getShortName());
    answer.setVisibility(constructorTemplate.getVisibility());
    for (Parameter parm : constructorTemplate.getParameters()) {
        answer.addParameter(parm);
    }

    for (String bodyLine : constructorTemplate.getBodyLines()) {
        answer.addBodyLine(bodyLine);
    }

    for (FullyQualifiedJavaType fqjt : constructorTemplate.getExceptions()) {
        answer.addException(fqjt);
    }

    commentGenerator.addGeneralMethodComment(answer, introspectedTable);

    return answer;
}
 
Example 2
Source File: InsertSelectiveMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
@Override
public void addInterfaceElements(Interface interfaze) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = new Method();

    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName(introspectedTable.getInsertSelectiveStatementId());

    FullyQualifiedJavaType parameterType = introspectedTable.getRules()
            .calculateAllFieldsClass();

    importedTypes.add(parameterType);
    method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    addMapperAnnotations(interfaze, method);
    
    if (context.getPlugins().clientInsertSelectiveMethodGenerated(
            method, interfaze, introspectedTable)) {
        interfaze.addImportedTypes(importedTypes);
        interfaze.addMethod(method);
    }
}
 
Example 3
Source File: DeleteByExampleMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
@Override
public void addInterfaceElements(Interface interfaze) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getExampleType());
    importedTypes.add(type);

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(introspectedTable.getDeleteByExampleStatementId());
    method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    addMapperAnnotations(interfaze, method);
    
    if (context.getPlugins().clientDeleteByExampleMethodGenerated(
            method, interfaze, introspectedTable)) {
        interfaze.addImportedTypes(importedTypes);
        interfaze.addMethod(method);
    }
}
 
Example 4
Source File: ExampleGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
private Method getNoValueMethod(IntrospectedColumn introspectedColumn,
        String nameFragment, String operator) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and"); //$NON-NLS-1$
    sb.append(nameFragment);
    method.setName(sb.toString());
    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
    sb.setLength(0);
    sb.append("addCriterion(\""); //$NON-NLS-1$
    sb.append(Ibatis2FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    sb.append(' ');
    sb.append(operator);
    sb.append("\");"); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$

    return method;
}
 
Example 5
Source File: DeleteByExampleMethodGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getExampleType());
    importedTypes.add(type);

    Method method = new Method();
    method.setVisibility(getExampleMethodVisibility());
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(getDAOMethodNameCalculator()
            .getDeleteByExampleMethodName(introspectedTable));
    method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    return method;
}
 
Example 6
Source File: PrimaryKeyGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
private void addParameterizedConstructor(TopLevelClass topLevelClass) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setConstructor(true);
    method.setName(topLevelClass.getType().getShortName());
    context.getCommentGenerator().addGeneralMethodComment(method, introspectedTable);
    
    StringBuilder sb = new StringBuilder();
    for (IntrospectedColumn introspectedColumn : introspectedTable
            .getPrimaryKeyColumns()) {
        method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(),
                introspectedColumn.getJavaProperty()));
        sb.setLength(0);
        sb.append("this."); //$NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty());
        sb.append(" = "); //$NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty());
        sb.append(';');
        method.addBodyLine(sb.toString());
    }
    
    topLevelClass.addMethod(method);
}
 
Example 7
Source File: CountByExampleMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
            introspectedTable.getExampleType());
    importedTypes.add(type);

    Method method = new Method();
    method.setVisibility(getExampleMethodVisibility());
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(getDAOMethodNameCalculator()
            .getCountByExampleMethodName(introspectedTable));
    method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    return method;
}
 
Example 8
Source File: UpdateByPrimaryKeyWithoutBLOBsMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
private Method getMethodShell(Set<FullyQualifiedJavaType> importedTypes) {
    FullyQualifiedJavaType parameterType = new FullyQualifiedJavaType(
            introspectedTable.getBaseRecordType());
    importedTypes.add(parameterType);

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method
            .setName(getDAOMethodNameCalculator()
                    .getUpdateByPrimaryKeyWithoutBLOBsMethodName(
                            introspectedTable));
    method.addParameter(new Parameter(parameterType, "record")); //$NON-NLS-1$

    for (FullyQualifiedJavaType fqjt : daoTemplate.getCheckedExceptions()) {
        method.addException(fqjt);
        importedTypes.add(fqjt);
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    return method;
}
 
Example 9
Source File: ExampleGenerator.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
private Method getNoValueMethod(IntrospectedColumn introspectedColumn,
        String nameFragment, String operator) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and"); //$NON-NLS-1$
    sb.append(nameFragment);
    method.setName(sb.toString());
    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
    sb.setLength(0);
    sb.append("addCriterion(\""); //$NON-NLS-1$
    sb.append(MyBatis3FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    sb.append(' ');
    sb.append(operator);
    sb.append("\");"); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$

    return method;
}
 
Example 10
Source File: AbstractJavaGenerator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
public static Method getGetter(Field field) {
    Method method = new Method();
    method.setName(getGetterMethodName(field.getName(), field
            .getType()));
    method.setReturnType(field.getType());
    method.setVisibility(JavaVisibility.PUBLIC);
    StringBuilder sb = new StringBuilder();
    sb.append("return "); //$NON-NLS-1$
    sb.append(field.getName());
    sb.append(';');
    method.addBodyLine(sb.toString());
    return method;
}
 
Example 11
Source File: UpdateByExampleSelectiveMethodGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public void addInterfaceElements(Interface interfaze) {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getIntInstance());
    method.setName(introspectedTable
            .getUpdateByExampleSelectiveStatementId());

    FullyQualifiedJavaType parameterType =
        introspectedTable.getRules().calculateAllFieldsClass();
    method.addParameter(new Parameter(parameterType,
            "record", "@Param(\"record\")")); //$NON-NLS-1$ //$NON-NLS-2$
    importedTypes.add(parameterType);

    FullyQualifiedJavaType exampleType = new FullyQualifiedJavaType(
            introspectedTable.getExampleType());
    method.addParameter(new Parameter(exampleType,
            "example", "@Param(\"example\")")); //$NON-NLS-1$ //$NON-NLS-2$
    importedTypes.add(exampleType);

    importedTypes.add(new FullyQualifiedJavaType(
            "org.apache.ibatis.annotations.Param")); //$NON-NLS-1$

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    addMapperAnnotations(interfaze, method);
    
    if (context.getPlugins()
            .clientUpdateByExampleSelectiveMethodGenerated(method, interfaze,
                    introspectedTable)) {
        interfaze.addImportedTypes(importedTypes);
        interfaze.addMethod(method);
    }
}
 
Example 12
Source File: RowBoundsPlugin.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
/**
 * Use the method copy constructor to create a new method, then
 * add the rowBounds parameter.
 * 
 * @param fullyQualifiedTable
 * @param method
 */
private void copyAndAddMethod(Method method, Interface interfaze) {
    Method newMethod = new Method(method);
    newMethod.setName(method.getName() + "WithRowbounds"); //$NON-NLS-1$
    newMethod.addParameter(new Parameter(rowBounds, "rowBounds")); //$NON-NLS-1$
    interfaze.addMethod(newMethod);
    interfaze.addImportedType(rowBounds);
}
 
Example 13
Source File: ToStringPlugin.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
private void generateToString(IntrospectedTable introspectedTable,
        TopLevelClass topLevelClass) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(FullyQualifiedJavaType.getStringInstance());
    method.setName("toString"); //$NON-NLS-1$
    if (introspectedTable.isJava5Targeted()) {
        method.addAnnotation("@Override"); //$NON-NLS-1$
    }

    context.getCommentGenerator().addGeneralMethodComment(method,
            introspectedTable);

    method.addBodyLine("StringBuilder sb = new StringBuilder();"); //$NON-NLS-1$
    method.addBodyLine("sb.append(getClass().getSimpleName());"); //$NON-NLS-1$
    method.addBodyLine("sb.append(\" [\");"); //$NON-NLS-1$
    method.addBodyLine("sb.append(\"Hash = \").append(hashCode());"); //$NON-NLS-1$
    StringBuilder sb = new StringBuilder();
    for (Field field : topLevelClass.getFields()) {
        String property = field.getName();
        sb.setLength(0);
        sb.append("sb.append(\"").append(", ").append(property) //$NON-NLS-1$ //$NON-NLS-2$
                .append("=\")").append(".append(").append(property) //$NON-NLS-1$ //$NON-NLS-2$
                .append(");"); //$NON-NLS-1$
        method.addBodyLine(sb.toString());
    }

    method.addBodyLine("sb.append(\"]\");"); //$NON-NLS-1$
    method.addBodyLine("return sb.toString();"); //$NON-NLS-1$

    topLevelClass.addMethod(method);
}
 
Example 14
Source File: BatchUpdateControllerGenerator.java    From maven-archetype with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static List<Method> generator(FullyQualifiedJavaType innerClassType,String beanName,
		String businessFieldName){
	List<Method> methodList = new ArrayList<Method>();
	
	String innerClassFiledName = StringUtils.uncapitalize(innerClassType.getShortName());
	
	Method method = new Method();
       method.addAnnotation("@RequestMapping(value = \"batchUpdateSave" + beanName + ".do\")");
       method.setVisibility(JavaVisibility.PUBLIC);
       method.setReturnType(new FullyQualifiedJavaType(String.class.getName()));
       method.setName("batchUpdateSave" + beanName);
       Parameter param1 = new Parameter(innerClassType, innerClassFiledName);
       param1.addAnnotation("@ModelAttribute ");
       Parameter paramModelMap = new Parameter(new FullyQualifiedJavaType(ModelMap.class.getName()), "map");
       method.addParameter(param1); 
       method.addParameter(paramModelMap); 
       // 方法body
       method.addBodyLine("try {");
       method.addBodyLine("if(" + innerClassFiledName + " != null && CollectionUtil.isNotNull(" + innerClassFiledName + ".get"+ beanName + "List())){");
       method.addBodyLine("int updateCount = this." + businessFieldName + ".update(" + innerClassFiledName + ".get"+ beanName + "List());");
       method.addBodyLine("if(updateCount >0 ){");
       method.addBodyLine("map.put(\"message\",\"更新成功。\");");
	method.addBodyLine("}else{");
	method.addBodyLine("map.put(\"message\",\"更新失败。\");");
       method.addBodyLine("}");
       method.addBodyLine("}");
       method.addBodyLine("} catch (Exception e) {");
       method.addBodyLine("logger.error(\"批量更新异常\" + e.getMessage());");
       method.addBodyLine("map.put(\"message\", \"批量更新异常\" + e.getMessage());");
       method.addBodyLine("}");
       method.addBodyLine(ControllerPluginUtil.RETURN);
       
	methodList.add(method);
	
    return methodList;
}
 
Example 15
Source File: AbstractJavaGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
public static Method getGetter(Field field) {
    Method method = new Method();
    method.setName(getGetterMethodName(field.getName(), field
            .getType()));
    method.setReturnType(field.getType());
    method.setVisibility(JavaVisibility.PUBLIC);
    StringBuilder sb = new StringBuilder();
    sb.append("return "); //$NON-NLS-1$
    sb.append(field.getName());
    sb.append(';');
    method.addBodyLine(sb.toString());
    return method;
}
 
Example 16
Source File: BatchUpdateControllerGenerator.java    From maven-archetype with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static List<Method> generator(FullyQualifiedJavaType innerClassType,String beanName,
		String businessFieldName){
	List<Method> methodList = new ArrayList<Method>();
	
	String innerClassFiledName = StringUtils.uncapitalize(innerClassType.getShortName());
	
	Method method = new Method();
       method.addAnnotation("@RequestMapping(value = \"batchUpdateSave" + beanName + ".do\")");
       method.addAnnotation("@ResponseBody");
       method.setVisibility(JavaVisibility.PUBLIC);
       method.setReturnType(new FullyQualifiedJavaType(AjaxResponseBean.class.getName()));
       method.setName("batchUpdateSave" + beanName);
       Parameter param1 = new Parameter(innerClassType, innerClassFiledName);
       param1.addAnnotation("@ModelAttribute ");
       method.addParameter(param1); 
       // 方法body
       method.addBodyLine("try {");
       method.addBodyLine("if(" + innerClassFiledName + " != null && CollectionUtil.isNotNull(" + innerClassFiledName + ".get"+ beanName + "List())){");
       method.addBodyLine("int updateCount = this." + businessFieldName + ".update(" + innerClassFiledName + ".get"+ beanName + "List());");
       method.addBodyLine("if(updateCount >0 ){");
       method.addBodyLine("return AjaxResponseBean.Const.SUCCESS_RESPONSE_BEAN;");
       method.addBodyLine("}");
       method.addBodyLine("}");
       method.addBodyLine("return AjaxResponseBean.Const.ERROR_RESPONSE_BEAN;");
       method.addBodyLine("} catch (Exception e) {");
       method.addBodyLine("logger.error(\"批量更新异常\" + e.getMessage());");
       method.addBodyLine("return AjaxResponseBean.getErrorResponseBean(\"批量更新异常\" + e.getMessage());");
       method.addBodyLine("}");
	methodList.add(method);
	
    return methodList;
}
 
Example 17
Source File: ExampleGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
private Method getSingleValueMethod(IntrospectedColumn introspectedColumn,
        String nameFragment, String operator) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.addParameter(new Parameter(introspectedColumn
            .getFullyQualifiedJavaType(), "value")); //$NON-NLS-1$
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and"); //$NON-NLS-1$
    sb.append(nameFragment);
    method.setName(sb.toString());
    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
    sb.setLength(0);

    if (introspectedColumn.isJDBCDateColumn()) {
        sb.append("addCriterionForJDBCDate(\""); //$NON-NLS-1$
    } else if (introspectedColumn.isJDBCTimeColumn()) {
        sb.append("addCriterionForJDBCTime(\""); //$NON-NLS-1$
    } else if (stringHasValue(introspectedColumn
            .getTypeHandler())) {
        sb.append("add"); //$NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty());
        sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
        sb.append("Criterion(\""); //$NON-NLS-1$
    } else {
        sb.append("addCriterion(\""); //$NON-NLS-1$
    }

    sb.append(MyBatis3FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    sb.append(' ');
    sb.append(operator);
    sb.append("\", "); //$NON-NLS-1$
    sb.append("value"); //$NON-NLS-1$
    sb.append(", \""); //$NON-NLS-1$
    sb.append(introspectedColumn.getJavaProperty());
    sb.append("\");"); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$

    return method;
}
 
Example 18
Source File: SelectListControllerGenerator.java    From maven-archetype with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static List<Method> generator(FullyQualifiedJavaType beanType,String beanName,
		String businessFieldName,String criteriaType){
	List<Method> methodList = new ArrayList<Method>();
	
	Method method = new Method();
       method.addAnnotation("@RequestMapping(value = \"select" + beanName + "List.do\")");
       method.setVisibility(JavaVisibility.PUBLIC);
       method.setReturnType(new FullyQualifiedJavaType(String.class.getName()));
       method.setName("select" + beanName + "List");
       Parameter param1 = new Parameter(new FullyQualifiedJavaType(Short.class.getName()), "conditionType");
       param1.addAnnotation("@RequestParam(\"conditionType\") ");
       Parameter param2 = new Parameter(FullyQualifiedJavaType.getStringInstance(), "conditionValue");
       param2.addAnnotation("@RequestParam(\"conditionValue\") ");
       Parameter param3 = new Parameter(new FullyQualifiedJavaType(PaginationBean.class.getName()), "paginationBean");
       param3.addAnnotation("@ModelAttribute ");
       Parameter paramModelMap = new Parameter(new FullyQualifiedJavaType(ModelMap.class.getName()), "map");
       method.addParameter(param1); 
       method.addParameter(param2); 
       method.addParameter(param3); 
       method.addParameter(paramModelMap); 
       // 方法body
       method.addBodyLine("try {");
       method.addBodyLine("int currentPage = paginationBean.getPageNum();");
       method.addBodyLine("int pageSize = paginationBean.getNumPerPage(); ");
       method.addBodyLine("");
       method.addBodyLine("if(pageSize < 1){");
       method.addBodyLine("map.put(\"message\",\"pageSize 错误。\"); ");
       method.addBodyLine(ControllerPluginUtil.RETURN);
       method.addBodyLine("}");
       method.addBodyLine("if(currentPage<1){");
       method.addBodyLine("map.put(\"message\",\"currentPage 错误。\"); ");
       method.addBodyLine(ControllerPluginUtil.RETURN);
       method.addBodyLine("}");
       method.addBodyLine("// 构造查询参数");
       method.addBodyLine(""+criteriaType + " param =new " + criteriaType + "();");
       method.addBodyLine("//"+criteriaType + ".Criteria criteria = param.createCriteria();");
       method.addBodyLine("");
       method.addBodyLine("// 根据参数设置查询条件");
       method.addBodyLine("");
       method.addBodyLine("// 取得当前查询的总记录结果");
       method.addBodyLine("int total = this." + businessFieldName + ".count" + beanName + "List(param);");
       method.addBodyLine("if(total == 0){");
       method.addBodyLine("// 没有记录数");
       method.addBodyLine("map.put(\"message\",\"没有记录。\"); ");
       method.addBodyLine(ControllerPluginUtil.RETURN);
       method.addBodyLine("}");
       method.addBodyLine("paginationBean.setTotalCount(total);");
       method.addBodyLine("// 判断当前请求的页码有没有超过总页数");
       method.addBodyLine("int totalPages = PaginationUtil.getPages(total, pageSize);");
       method.addBodyLine("paginationBean.setTotalPages(totalPages);");
       method.addBodyLine("");
       method.addBodyLine("if(currentPage > totalPages){");
       method.addBodyLine("// 当前页超过总页数,取最大数");
       method.addBodyLine("currentPage = totalPages;");
       method.addBodyLine("paginationBean.setPageNum(currentPage);");
       method.addBodyLine("}");
       method.addBodyLine("");
       method.addBodyLine("// 设置排序");
       method.addBodyLine("// param.setOrderByClause(\" id asc \");");
       method.addBodyLine("");
       method.addBodyLine("int start = (currentPage - 1) * pageSize;");
       method.addBodyLine("param.setStart(start);");
       method.addBodyLine("param.setCount(pageSize);");
       method.addBodyLine("");
       method.addBodyLine("List<" + beanName + "> " + StringUtils.uncapitalize(beanName) +"List = this." + businessFieldName + ".select" + beanName + "List(param);");
       method.addBodyLine("");
       method.addBodyLine("paginationBean.setResult(" + StringUtils.uncapitalize(beanName) +"List);  // 返回数据结果");
       method.addBodyLine("map.put(\"message\",JSON.toJSONString(" + StringUtils.uncapitalize(beanName) +"List));");
       method.addBodyLine("} catch (Exception e) {");
       method.addBodyLine("logger.error(\"查询异常\" + e.getMessage());");
       method.addBodyLine("map.put(\"message\", \"查询异常\" + e.getMessage());");
       method.addBodyLine("}"); 
       method.addBodyLine(ControllerPluginUtil.RETURN);
       
	methodList.add(method);
       
       return methodList;
}
 
Example 19
Source File: ExampleGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @param introspectedColumn
 * @param inMethod
 *            if true generates an "in" method, else generates a "not in"
 *            method
 * @return a generated method for the in or not in method
 */
private Method getSetInOrNotInMethod(IntrospectedColumn introspectedColumn,
        boolean inMethod) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    FullyQualifiedJavaType type = FullyQualifiedJavaType
            .getNewListInstance();
    if (introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) {
        type.addTypeArgument(introspectedColumn.getFullyQualifiedJavaType()
                .getPrimitiveTypeWrapper());
    } else {
        type
                .addTypeArgument(introspectedColumn
                        .getFullyQualifiedJavaType());
    }

    method.addParameter(new Parameter(type, "values")); //$NON-NLS-1$
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and"); //$NON-NLS-1$
    if (inMethod) {
        sb.append("In"); //$NON-NLS-1$
    } else {
        sb.append("NotIn"); //$NON-NLS-1$
    }
    method.setName(sb.toString());
    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
    sb.setLength(0);

    if (introspectedColumn.isJDBCDateColumn()) {
        sb.append("addCriterionForJDBCDate(\""); //$NON-NLS-1$
    } else if (introspectedColumn.isJDBCTimeColumn()) {
        sb.append("addCriterionForJDBCTime(\""); //$NON-NLS-1$
    } else if (stringHasValue(introspectedColumn
            .getTypeHandler())) {
        sb.append("add"); //$NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty());
        sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
        sb.append("Criterion(\""); //$NON-NLS-1$
    } else {
        sb.append("addCriterion(\""); //$NON-NLS-1$
    }

    sb.append(MyBatis3FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    if (inMethod) {
        sb.append(" in"); //$NON-NLS-1$
    } else {
        sb.append(" not in"); //$NON-NLS-1$
    }
    sb.append("\", values, \""); //$NON-NLS-1$
    sb.append(introspectedColumn.getJavaProperty());
    sb.append("\");"); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$

    return method;
}
 
Example 20
Source File: ExampleGenerator.java    From mybatis-generator-plus with Apache License 2.0 4 votes vote down vote up
/**
 * Generates methods that set between and not between conditions
 * 
 * @param introspectedColumn
 * @param betweenMethod
 * @return a generated method for the between or not between method
 */
private Method getSetBetweenOrNotBetweenMethod(
        IntrospectedColumn introspectedColumn, boolean betweenMethod) {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    FullyQualifiedJavaType type = introspectedColumn
            .getFullyQualifiedJavaType();

    method.addParameter(new Parameter(type, "value1")); //$NON-NLS-1$
    method.addParameter(new Parameter(type, "value2")); //$NON-NLS-1$
    StringBuilder sb = new StringBuilder();
    sb.append(introspectedColumn.getJavaProperty());
    sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
    sb.insert(0, "and"); //$NON-NLS-1$
    if (betweenMethod) {
        sb.append("Between"); //$NON-NLS-1$
    } else {
        sb.append("NotBetween"); //$NON-NLS-1$
    }
    method.setName(sb.toString());
    method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
    sb.setLength(0);

    if (introspectedColumn.isJDBCDateColumn()) {
        sb.append("addCriterionForJDBCDate(\""); //$NON-NLS-1$
    } else if (introspectedColumn.isJDBCTimeColumn()) {
        sb.append("addCriterionForJDBCTime(\""); //$NON-NLS-1$
    } else if (stringHasValue(introspectedColumn
            .getTypeHandler())) {
        sb.append("add"); //$NON-NLS-1$
        sb.append(introspectedColumn.getJavaProperty());
        sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
        sb.append("Criterion(\""); //$NON-NLS-1$
    } else {
        sb.append("addCriterion(\""); //$NON-NLS-1$
    }

    sb.append(Ibatis2FormattingUtilities
            .getAliasedActualColumnName(introspectedColumn));
    if (betweenMethod) {
        sb.append(" between"); //$NON-NLS-1$
    } else {
        sb.append(" not between"); //$NON-NLS-1$
    }
    sb.append("\", "); //$NON-NLS-1$
    if (introspectedColumn.getFullyQualifiedJavaType().isPrimitive() && !introspectedTable.isJava5Targeted()) {
        sb.append("new "); //$NON-NLS-1$
        sb.append(introspectedColumn.getFullyQualifiedJavaType()
                .getPrimitiveTypeWrapper().getShortName());
        sb.append("(value1), "); //$NON-NLS-1$
        sb.append("new "); //$NON-NLS-1$
        sb.append(introspectedColumn.getFullyQualifiedJavaType()
                .getPrimitiveTypeWrapper().getShortName());
        sb.append("(value2)"); //$NON-NLS-1$
    } else {
        sb.append("value1, value2"); //$NON-NLS-1$
    }

    sb.append(", \""); //$NON-NLS-1$
    sb.append(introspectedColumn.getJavaProperty());
    sb.append("\");"); //$NON-NLS-1$
    method.addBodyLine(sb.toString());
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$

    return method;
}