Package org.mybatis.generator.api.dom.java

Examples of org.mybatis.generator.api.dom.java.Method


    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    FullyQualifiedJavaType returnType = new FullyQualifiedJavaType("java.util.LinkedHashMap");
    returnType.addTypeArgument(new FullyQualifiedJavaType("java.lang.String"));
    returnType.addTypeArgument(new FullyQualifiedJavaType("java.util.List"));
    importedTypes.add(returnType);
    Method method = new Method();
    method.addAnnotation("@Override");
    method.addSuppressTypeWarningsAnnotation();
    method.setReturnType(returnType);
    topLevelClass.addImportedTypes(importedTypes);
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("getExportData");
    method.addBodyLine("LinkedHashMap<String, List> map = new LinkedHashMap<String, List>();");
    method.addBodyLine("map.put(\"SheetName_1\", findAll());");
    method.addBodyLine("map.put(\"SheetName_2\", findAll());");
    method.addBodyLine("map.put(\"SheetName_3\", findAll());");
    method.addBodyLine("map.put(\"SheetName_N\", findAll());");
    method.addBodyLine("return map;");
    topLevelClass.addMethod(method);
  }
View Full Code Here


  {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    FullyQualifiedJavaType returnType = FullyQualifiedJavaType.getNewListInstance();
    returnType.addTypeArgument(new FullyQualifiedJavaType(introspectedTable.getBaseRecordType()));
    importedTypes.add(returnType);
    Method method = new Method();
    method.setReturnType(returnType);
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("findByCriteria");
    FullyQualifiedJavaType pType = new FullyQualifiedJavaType(
        introspectedTable.getExampleType());
    importedTypes.add(pType);
    method.addParameter(new Parameter(pType, "criteria"));
    method
        .addBodyLine("return " + mapperObjName + ".selectByCriteria(criteria);");
    method.addAnnotation("@Override");
    topLevelClass.addImportedTypes(importedTypes);
    topLevelClass.addMethod(method);
  }
View Full Code Here

    FullyQualifiedJavaType returnType = FullyQualifiedJavaType
        .getNewListInstance();
    returnType.addTypeArgument(new FullyQualifiedJavaType(introspectedTable
        .getBaseRecordType()));
    importedTypes.add(returnType);
    Method method = new Method();
    method.setReturnType(returnType);
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("findAll");
    method
        .addBodyLine("return " + mapperObjName + ".selectByCriteria(null);");
    method.addAnnotation("@Override");
    topLevelClass.addImportedTypes(importedTypes);
    topLevelClass.addMethod(method);
  }
View Full Code Here

  {
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    FullyQualifiedJavaType returnType = new FullyQualifiedJavaType(
        introspectedTable.getBaseRecordType());
    importedTypes.add(returnType);
    Method method = new Method();
    method.setReturnType(returnType);
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("findById");
    method.addParameter(new Parameter(
        new FullyQualifiedJavaType("long"), "id"))
    // return userMapper.selectByPrimaryKey(id);
    method
        .addBodyLine("return " + mapperObjName + ".selectByPrimaryKey(id);");
    method.addAnnotation("@Override");
    topLevelClass.addImportedTypes(importedTypes);
    topLevelClass.addMethod(method);
  }
View Full Code Here

    importedTypes.add(type);

    FullyQualifiedJavaType returnType = new FullyQualifiedJavaType(
        "com.eatle.utils.Pagination");
    importedTypes.add(returnType);
    Method method = new Method();
    method.setReturnType(returnType);
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("findPagination");
    method.addParameter(new Parameter(type, "queryMap"))
    method.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), "currentPage"));// int currentPage
    method.addParameter(new Parameter(FullyQualifiedJavaType .getIntInstance(), "pageSize"));// int pageSize
    method.addBodyLine("" + recordFullType + "Criteria " + recordLowCaseFullType + "Criteria = new " + recordFullType + "Criteria();");
    method.addBodyLine("//Criteria criteria = " + recordLowCaseFullType + "Criteria.createCriteria();");
    method.addBodyLine("// 设置搜索条件参数");
    method.addBodyLine("//if(queryMap != null){");
    method.addBodyLine("//if(queryMap.containsKey(\"username\")) {");
    method.addBodyLine("//criteria.andUserNameLike(\"%\"+(String)queryMap.get(\"username\")+\"%\");");
    method.addBodyLine("//}");
    method.addBodyLine("//if(queryMap.containsKey(\"email\")){");
    method.addBodyLine("//criteria.andEmailLike((String)queryMap.get(\"email\"));");
    method.addBodyLine("//}");
    method.addBodyLine("//}");
    method.addBodyLine("// 设置分页参数");
    method.addBodyLine(recordLowCaseFullType + "Criteria.setPageSize(pageSize);");
    method.addBodyLine(recordLowCaseFullType + "Criteria.setStartIndex((currentPage-1)*pageSize);");
    method.addBodyLine("List<" + recordFullType + "> items = " + mapperObjName + ".selectByCriteria(" + recordLowCaseFullType + "Criteria);");
    method.addBodyLine("int totalCount = (int)" + mapperObjName + ".selectCountByCriteria(" + recordLowCaseFullType + "Criteria);");
    method.addBodyLine("return new Pagination(pageSize, currentPage, totalCount, items);");
    method.addAnnotation("@Override");

    // import com.eatle.persistent.pojo.admin.ObjectCriteria.Criteria;
    FullyQualifiedJavaType pType = new FullyQualifiedJavaType(
        introspectedTable.getExampleType() + ".Criteria");
    importedTypes.add(pType);
View Full Code Here

    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    FullyQualifiedJavaType type = new FullyQualifiedJavaType(
        introspectedTable.getExampleType());
    importedTypes.add(type);

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);

    FullyQualifiedJavaType returnType = new FullyQualifiedJavaType("long");
    method.setReturnType(returnType);

    method.setName("selectCount"
        + introspectedTable.getSelectByExampleStatementId()
            .substring(6));
    method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$ 
    method.addJavaDocLine("/**");
    method.addJavaDocLine(" * @Description : 根据查询条件获取总的记录数量");
    method.addJavaDocLine(" */");

    interfaze.addImportedTypes(importedTypes);
    interfaze.addMethod(method);
  }
 
View Full Code Here

    FullyQualifiedJavaType type = FullyQualifiedJavaType
        .getNewMapInstance();
    importedTypes.add(type);
    importedTypes.add(FullyQualifiedJavaType.getNewListInstance());

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);

    FullyQualifiedJavaType returnType = FullyQualifiedJavaType
        .getNewListInstance();
    FullyQualifiedJavaType listType;
    if (introspectedTable.getRules().generateBaseRecordClass())
    {
      listType = new FullyQualifiedJavaType(introspectedTable
          .getBaseRecordType());
    }
    else if (introspectedTable.getRules().generatePrimaryKeyClass())
    {
      listType = new FullyQualifiedJavaType(introspectedTable
          .getPrimaryKeyType());
    }
    else
    {
      throw new RuntimeException(getString("RuntimeError.12")); //$NON-NLS-1$ 
    }

    importedTypes.add(listType);
    returnType.addTypeArgument(listType);
    method.setReturnType(returnType);

    method.setName("selectByMap");
    method.addParameter(new Parameter(type, "paramMap")); //$NON-NLS-1$ 
    method.addSuppressTypeWarningsAnnotation();
    method.addJavaDocLine("/**");
    method.addJavaDocLine(" * @Description : 通过map参数进行查询");
    method.addJavaDocLine(" */");

    interfaze.addImportedTypes(importedTypes);
    interfaze.addMethod(method);
  }
 
View Full Code Here

    Field tmpField = new Field(fieldName, fieldType);
    tmpField.setVisibility(JavaVisibility.PRIVATE);
    tmpField.addJavaDocLine(javaDocLine);
    topLevelClass.addField(tmpField);

    Method setMethod = new Method();
    setMethod.setName("set" + fieldName.toUpperCase().substring(0, 1)
        + fieldName.substring(1));
    Parameter param = new Parameter(fieldType, fieldName);
    setMethod.addParameter(param);
    setMethod.setVisibility(JavaVisibility.PUBLIC);
    setMethod.addBodyLine("this." + fieldName + "=" + fieldName + ";");

    topLevelClass.addMethod(setMethod);

    Method getMethod = new Method();
    getMethod.setName("get" + fieldName.toUpperCase().substring(0, 1)
        + fieldName.substring(1));

    getMethod.setReturnType(fieldType);
    getMethod.setVisibility(JavaVisibility.PUBLIC);
    getMethod.addBodyLine("return this." + fieldName + ";");

    topLevelClass.addMethod(getMethod);

  }
View Full Code Here

    FullyQualifiedJavaType intType = FullyQualifiedJavaType
        .getIntInstance();
    addField("startIndex", intType, topLevelClass, "// 开始索引号");
    addField("pageSize", intType, topLevelClass, "// 每页大小");

    Method newConstructorMethod = new Method();
    newConstructorMethod.setConstructor(true);
    newConstructorMethod.addParameter(new Parameter(intType, "pageSize"));
    newConstructorMethod.addParameter(new Parameter(intType, "startIndex"));
    newConstructorMethod.addBodyLine("this();");
    newConstructorMethod.addBodyLine("this.pageSize=pageSize;");
    newConstructorMethod.addBodyLine("this.startIndex=startIndex;");
    newConstructorMethod.setVisibility(JavaVisibility.PUBLIC);
    newConstructorMethod.setName(topLevelClass.getType().getShortName());

    topLevelClass.addMethod(newConstructorMethod);
    return true;
  }
View Full Code Here

   */
  private void addGetBaseRecordMethod(TopLevelClass topLevelClass,
      IntrospectedTable introspectedTable, String recordFullType,
      String recordLowerFullType)
  {
    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(new FullyQualifiedJavaType(introspectedTable
        .getBaseRecordType()));
    method.setName("get" + recordFullType); //$NON-NLS-1$
    method.addBodyLine("return this." + recordLowerFullType + ";"); //$NON-NLS-1$
    topLevelClass.addMethod(method);
  }
View Full Code Here

TOP

Related Classes of org.mybatis.generator.api.dom.java.Method

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.