Examples of TopLevelClass


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

    // import ...
    type = new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
    importedTypes.add(type);

    type = new FullyQualifiedJavaType(actionFullName);
    TopLevelClass topLevelClass = new TopLevelClass(type);
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    type = new FullyQualifiedJavaType("com.eatle.web.action.BaseAction");
    topLevelClass.setSuperClass(type);
    importedTypes.add(type);
    // add field, getter, setter for orderby clause
    // @Resource
    // private IUserService userService;
    type = new FullyQualifiedJavaType("javax.annotation.Resource");
    importedTypes.add(type);
    Field field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    type = new FullyQualifiedJavaType(serviceInterfaceFullName);
    importedTypes.add(type);
    field.setType(type);
    field.setName(serviceObjName); //$NON-NLS-1$
    field.addAnnotation("@Resource");
    topLevelClass.addField(field);

    // private Pagination page;
    field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    type = new FullyQualifiedJavaType("com.eatle.utils.Pagination");
    importedTypes.add(type);
    field.setType(type);
    field.setName("page");
    topLevelClass.addField(field);

    field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    type = new FullyQualifiedJavaType(recordFullType);
    field.setType(type);
    field.setName(recordLowerFullType);
    topLevelClass.addField(field);
    topLevelClass.addImportedTypes(importedTypes);
    // setter getter
    addSetPageMethod(topLevelClass, introspectedTable);
    addGetPageMethod(topLevelClass, introspectedTable);
    addGetBaseRecordMethod(topLevelClass, introspectedTable,
        recordFullType, recordLowerFullType);
View Full Code Here

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

    // 生成Service实现类
    String serviceImplFullName = serveiceImplPackge + "." + recordFullType + "ServiceImpl";
    Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
    importedTypes.add(type)// 导入接口
    type = new FullyQualifiedJavaType(serviceImplFullName);
    TopLevelClass topLevelClass = new TopLevelClass(type);
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    type = new FullyQualifiedJavaType(serviceInterfaceFullName);
    topLevelClass.addSuperInterface(type);
    topLevelClass.addAnnotation("@Service(\"" + recordLowCaseFullType + "Service\")");
    type = new FullyQualifiedJavaType("org.springframework.stereotype.Service");
    importedTypes.add(type);

    // add field, getter, setter for orderby clause
    // @Resource private UserMapper userMapper;
    type = new FullyQualifiedJavaType("javax.annotation.Resource");
    importedTypes.add(type);

    Field field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    String mapper = introspectedTable.getMyBatis3JavaMapperType();
    type = new FullyQualifiedJavaType(mapper);
    field.setType(type);
    idx = mapper.lastIndexOf(".");
    if (idx != -1)
    {
      mapper = mapper.substring(idx + 1);
    }
    mapper = mapper.substring(0, 1).toLowerCase() + mapper.substring(1);
    field.setName(mapper);
    field.addAnnotation("@Resource");
    topLevelClass.addField(field);
    importedTypes.add(type);
    topLevelClass.addImportedTypes(importedTypes);

    // add Method....
    addAddMethod(topLevelClass, introspectedTable);
    addDeleteMethod(topLevelClass, introspectedTable);
    addUpdateMethod(topLevelClass, introspectedTable);
View Full Code Here

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

    pojoType = new FullyQualifiedJavaType(pojoUrl + "." + tableName);

    pojoCriteriaType = new FullyQualifiedJavaType(pojoUrl + "." + tableName + "Example");
    listType = new FullyQualifiedJavaType("java.util.List");
    Interface interface1 = new Interface(interfaceType);
    TopLevelClass topLevelClass = new TopLevelClass(serviceType);
    // 导入必要的类
    addImport(interface1, topLevelClass);

    // 接口
    addService(interface1,introspectedTable, tableName, files);
View Full Code Here

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

  @Override
  public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {

    List<GeneratedJavaFile> files = new ArrayList<GeneratedJavaFile>();
    TopLevelClass topLevelClass = new TopLevelClass(criteria);
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    addClassComment(topLevelClass, "公用条件查询类");
    topLevelClass.addImportedType(FullyQualifiedJavaType.getNewMapInstance());
    topLevelClass.addImportedType(FullyQualifiedJavaType.getNewHashMapInstance());

    FullyQualifiedJavaType types = new FullyQualifiedJavaType("java.util.Map<java.lang.String, java.lang.Object>");
    Rules rules = introspectedTable.getRules();
    if (rules.generateUpdateByExampleSelective() || rules.generateUpdateByExampleWithBLOBs()
        || rules.generateUpdateByExampleWithoutBLOBs()) {
      Method method = new Method();
      method.setVisibility(JavaVisibility.PROTECTED);
      method.setConstructor(true);
      method.setName(criteria.getShortName());
      method.addParameter(new Parameter(criteria, "example")); //$NON-NLS-1$
      method.addBodyLine("this.orderByClause = example.orderByClause;"); //$NON-NLS-1$
      method.addBodyLine("this.condition = example.condition;"); //$NON-NLS-1$
      method.addBodyLine("this.distinct = example.distinct;"); //$NON-NLS-1$
      method.addBodyLine("this.limit = example.limit;"); //$NON-NLS-1$
      method.addBodyLine("this.start = example.start;"); //$NON-NLS-1$
      topLevelClass.addMethod(method);
    }

    Field field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(types);
    field.setName("condition"); //$NON-NLS-1$
    addFieldComment(field, "存放条件查询值");
    topLevelClass.addField(field);

    // add field, getter, setter for distinct
    field = new Field();
    field.setVisibility(JavaVisibility.PROTECTED);
    field.setType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
    field.setName("distinct"); //$NON-NLS-1$
    addFieldComment(field, "是否相异");
    topLevelClass.addField(field);

    // add field, getter, setter for orderby clause
    field = new Field();
    field.setVisibility(JavaVisibility.PROTECTED);
    field.setType(FullyQualifiedJavaType.getStringInstance());
    field.setName("orderByClause"); //$NON-NLS-1$
    addFieldComment(field, "排序字段");
    topLevelClass.addField(field);

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setConstructor(true);
    method.setName("Criteria"); //$NON-NLS-1$
    method.addBodyLine("condition = new HashMap<String, Object>();"); //$NON-NLS-1$
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("clear"); //$NON-NLS-1$
    method.addBodyLine("condition.clear();"); //$NON-NLS-1$
    method.addBodyLine("orderByClause = null;"); //$NON-NLS-1$
    method.addBodyLine("distinct = false;"); //$NON-NLS-1$
    method.addBodyLine("this.limit=null;"); //$NON-NLS-1$
    method.addBodyLine("this.start=null;"); //$NON-NLS-1$
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(criteria);
    method.setName("put"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "condition")); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), "value")); //$NON-NLS-1$
    method.addBodyLine("this.condition.put(condition, value);"); //$NON-NLS-1$
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$
    addSetterComment(method, OutputUtilities.lineSeparator+"\t *            查询的条件名称"+OutputUtilities.lineSeparator+"\t * @param value"+OutputUtilities.lineSeparator+"\t *            查询的值", "condition");
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setOrderByClause"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "orderByClause")); //$NON-NLS-1$
    method.addBodyLine("this.orderByClause = orderByClause;"); //$NON-NLS-1$
    addSetterComment(method, OutputUtilities.lineSeparator+"\t *            排序字段", "orderByClause");
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setDistinct"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getBooleanPrimitiveInstance(), "distinct")); //$NON-NLS-1$
    method.addBodyLine("this.distinct = distinct;"); //$NON-NLS-1$
    addSetterComment(method, OutputUtilities.lineSeparator+"\t *            是否相异", "distinct");
    topLevelClass.addMethod(method);

    field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(FullyQualifiedJavaType.getInteger());
    field.setName("limit"); //$NON-NLS-1$
    topLevelClass.addField(field);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setLimit"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getInteger(), "limit")); //$NON-NLS-1$
    method.addBodyLine("this.limit = limit;"); //$NON-NLS-1$
    addSetterComment(method, "每页大小,即mysql中的length", "limit");
    topLevelClass.addMethod(method);

    field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(FullyQualifiedJavaType.getInteger());
    field.setName("start"); //$NON-NLS-1$
    topLevelClass.addField(field);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setStart"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getInteger(), "start")); //$NON-NLS-1$
    method.addBodyLine("this.start = start;"); //$NON-NLS-1$
    addSetterComment(method, "开始行数,即mysql中的offset", "start");
    topLevelClass.addMethod(method);


    GeneratedJavaFile file = new GeneratedJavaFile(topLevelClass, context.getJavaModelGeneratorConfiguration()
        .getTargetProject());
    files.add(file);
View Full Code Here

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

    progressCallback.startTask(getString("Progress.18", //$NON-NLS-1$
        introspectedTable.getFullyQualifiedTable().toString()));
    CommentGenerator commentGenerator = context.getCommentGenerator();

    FullyQualifiedJavaType type = new FullyQualifiedJavaType(introspectedTable.getMyBatis3SqlProviderType());
    TopLevelClass topLevelClass = new TopLevelClass(type);
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    commentGenerator.addJavaFileComment(topLevelClass);

    boolean addApplyWhereMethod = false;
    addApplyWhereMethod |= addCountByExampleMethod(topLevelClass);
    addApplyWhereMethod |= addDeleteByExampleMethod(topLevelClass);
    addInsertSelectiveMethod(topLevelClass);
    addApplyWhereMethod |= addSelectByExampleWithBLOBsMethod(topLevelClass);
    addApplyWhereMethod |= addSelectByExampleWithoutBLOBsMethod(topLevelClass);
    addApplyWhereMethod |= addUpdateByExampleSelectiveMethod(topLevelClass);
    addApplyWhereMethod |= addUpdateByExampleWithBLOBsMethod(topLevelClass);
    addApplyWhereMethod |= addUpdateByExampleWithoutBLOBsMethod(topLevelClass);
    addUpdateByPrimaryKeySelectiveMethod(topLevelClass);

    if (addApplyWhereMethod) {
      addApplyWhereMethod(topLevelClass);
    }

    List<CompilationUnit> answer = new ArrayList<CompilationUnit>();

    if (topLevelClass.getMethods().size() > 0) {
      if (context.getPlugins().providerGenerated(topLevelClass, introspectedTable)) {
        answer.add(topLevelClass);
      }
    }
View Full Code Here

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

  @Override
  public List<CompilationUnit> getCompilationUnits() {
    FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
    progressCallback.startTask(getString("Progress.14", table.toString())); //$NON-NLS-1$
    TopLevelClass topLevelClass = getTopLevelClassShell();
    Interface interfaze = getInterfaceShell();

    addCountByExampleMethod(topLevelClass, interfaze);
    addDeleteByExampleMethod(topLevelClass, interfaze);
    addDeleteByPrimaryKeyMethod(topLevelClass, interfaze);
View Full Code Here

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

    FullyQualifiedJavaType implementationType = new FullyQualifiedJavaType(
        introspectedTable.getDAOImplementationType());

    CommentGenerator commentGenerator = context.getCommentGenerator();

    TopLevelClass answer = new TopLevelClass(implementationType);
    answer.setVisibility(JavaVisibility.PUBLIC);
    answer.setSuperClass(daoTemplate.getSuperClass());
    answer.addImportedType(daoTemplate.getSuperClass());
    answer.addSuperInterface(interfaceType);
    answer.addImportedType(interfaceType);

    for (FullyQualifiedJavaType fqjt : daoTemplate.getImplementationImports()) {
      answer.addImportedType(fqjt);
    }

    commentGenerator.addJavaFileComment(answer);

    // add constructor from the template
    answer.addMethod(daoTemplate.getConstructorClone(commentGenerator, implementationType, introspectedTable));

    // add any fields from the template
    for (Field field : daoTemplate.getFieldClones(commentGenerator, introspectedTable)) {
      answer.addField(field);
    }

    // add any methods from the template
    for (Method method : daoTemplate.getMethodClones(commentGenerator, introspectedTable)) {
      answer.addMethod(method);
    }

    return answer;
  }
View Full Code Here

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

  @Override
  public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {

    List<GeneratedJavaFile> files = new ArrayList<GeneratedJavaFile>();
    TopLevelClass topLevelClass = new TopLevelClass(criteria);
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    addClassComment(topLevelClass, "公用条件查询类");
    topLevelClass.addImportedType(FullyQualifiedJavaType.getNewMapInstance());
    topLevelClass.addImportedType(FullyQualifiedJavaType.getNewHashMapInstance());

    FullyQualifiedJavaType types = new FullyQualifiedJavaType("java.util.Map<java.lang.String, java.lang.Object>");
    Rules rules = introspectedTable.getRules();
    if (rules.generateUpdateByExampleSelective() || rules.generateUpdateByExampleWithBLOBs()
        || rules.generateUpdateByExampleWithoutBLOBs()) {
      Method method = new Method();
      method.setVisibility(JavaVisibility.PROTECTED);
      method.setConstructor(true);
      method.setName(criteria.getShortName());
      method.addParameter(new Parameter(criteria, "example")); //$NON-NLS-1$
      method.addBodyLine("this.orderByClause = example.orderByClause;"); //$NON-NLS-1$
      method.addBodyLine("this.condition = example.condition;"); //$NON-NLS-1$
      method.addBodyLine("this.distinct = example.distinct;"); //$NON-NLS-1$
      method.addBodyLine("this.limit = example.limit;"); //$NON-NLS-1$
      method.addBodyLine("this.start = example.start;"); //$NON-NLS-1$
      topLevelClass.addMethod(method);
    }

    Field field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(types);
    field.setName("condition"); //$NON-NLS-1$
    addFieldComment(field, "存放条件查询值");
    topLevelClass.addField(field);

    // add field, getter, setter for distinct
    field = new Field();
    field.setVisibility(JavaVisibility.PROTECTED);
    field.setType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
    field.setName("distinct"); //$NON-NLS-1$
    addFieldComment(field, "是否相异");
    topLevelClass.addField(field);

    // add field, getter, setter for orderby clause
    field = new Field();
    field.setVisibility(JavaVisibility.PROTECTED);
    field.setType(FullyQualifiedJavaType.getStringInstance());
    field.setName("orderByClause"); //$NON-NLS-1$
    addFieldComment(field, "排序字段");
    topLevelClass.addField(field);

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setConstructor(true);
    method.setName("Criteria"); //$NON-NLS-1$
    method.addBodyLine("this.condition = new HashMap<String, Object>();"); //$NON-NLS-1$
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("clear"); //$NON-NLS-1$
    method.addBodyLine("this.condition.clear();"); //$NON-NLS-1$
    method.addBodyLine("this.orderByClause = null;"); //$NON-NLS-1$
    method.addBodyLine("this.distinct = false;"); //$NON-NLS-1$
    method.addBodyLine("this.limit=null;"); //$NON-NLS-1$
    method.addBodyLine("this.start=null;"); //$NON-NLS-1$
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(criteria);
    method.setName("put"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "condition")); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), "value")); //$NON-NLS-1$
    method.addBodyLine("this.condition.put(condition, value);"); //$NON-NLS-1$
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$
    addSetterComment(method, OutputUtilities.lineSeparator+"\t *            查询的条件名称"+OutputUtilities.lineSeparator+"\t * @param value"+OutputUtilities.lineSeparator+"\t *            查询的值", "condition");
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setOrderByClause"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "orderByClause")); //$NON-NLS-1$
    method.addBodyLine("this.orderByClause = orderByClause;"); //$NON-NLS-1$
    addSetterComment(method, OutputUtilities.lineSeparator+"\t *            排序字段", "orderByClause");
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setDistinct"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getBooleanPrimitiveInstance(), "distinct")); //$NON-NLS-1$
    method.addBodyLine("this.distinct = distinct;"); //$NON-NLS-1$
    addSetterComment(method, OutputUtilities.lineSeparator+"\t *            是否相异", "distinct");
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setCondition"); //$NON-NLS-1$
    method.addParameter(new Parameter(types, "condition")); //$NON-NLS-1$
    method.addBodyLine("this.condition = condition;"); //$NON-NLS-1$
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(types);
    method.setName("getCondition"); //$NON-NLS-1$
    method.addBodyLine("return condition;"); //$NON-NLS-1$
    topLevelClass.addMethod(method);

    field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(FullyQualifiedJavaType.getInteger());
    field.setName("limit"); //$NON-NLS-1$
    addFieldComment(field, "每页大小,即mysql中的length");
    topLevelClass.addField(field);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setLimit"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getInteger(), "limit")); //$NON-NLS-1$
    method.addBodyLine("this.limit = limit;"); //$NON-NLS-1$
    addSetterComment(method, OutputUtilities.lineSeparator+"\t *            每页大小,即mysql中的length", "limit");
    topLevelClass.addMethod(method);

    field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(FullyQualifiedJavaType.getInteger());
    field.setName("start"); //$NON-NLS-1$
    addFieldComment(field, "开始行数,即mysql中的offset");
    topLevelClass.addField(field);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setStart"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getInteger(), "start")); //$NON-NLS-1$
    method.addBodyLine("this.start = start;"); //$NON-NLS-1$
    addSetterComment(method, OutputUtilities.lineSeparator+"\t *            开始行数,即mysql中的offset", "start");
    topLevelClass.addMethod(method);

    GeneratedJavaFile file = new GeneratedJavaFile(topLevelClass, context.getJavaModelGeneratorConfiguration()
        .getTargetProject());
    files.add(file);
    return files;
View Full Code Here

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

  @Override
  public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {

    List<GeneratedJavaFile> files = new ArrayList<GeneratedJavaFile>();
    TopLevelClass topLevelClass = new TopLevelClass(criteria);
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);
    addClassComment(topLevelClass, "公用条件查询类");
    topLevelClass.addImportedType(FullyQualifiedJavaType.getNewMapInstance());
    topLevelClass.addImportedType(FullyQualifiedJavaType.getNewHashMapInstance());

    FullyQualifiedJavaType types = new FullyQualifiedJavaType("java.util.Map<java.lang.String, java.lang.Object>");
    Rules rules = introspectedTable.getRules();
    if (rules.generateUpdateByExampleSelective() || rules.generateUpdateByExampleWithBLOBs()
        || rules.generateUpdateByExampleWithoutBLOBs()) {
      Method method = new Method();
      method.setVisibility(JavaVisibility.PROTECTED);
      method.setConstructor(true);
      method.setName(criteria.getShortName());
      method.addParameter(new Parameter(criteria, "example")); //$NON-NLS-1$
      method.addBodyLine("this.orderByClause = example.orderByClause;"); //$NON-NLS-1$
      method.addBodyLine("this.condition = example.condition;"); //$NON-NLS-1$
      method.addBodyLine("this.distinct = example.distinct;"); //$NON-NLS-1$
      method.addBodyLine("this.limit = example.limit;"); //$NON-NLS-1$
      method.addBodyLine("this.start = example.start;"); //$NON-NLS-1$
      topLevelClass.addMethod(method);
    }

    Field field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(types);
    field.setName("condition"); //$NON-NLS-1$
    addFieldComment(field, "存放条件查询值");
    topLevelClass.addField(field);

    // add field, getter, setter for distinct
    field = new Field();
    field.setVisibility(JavaVisibility.PROTECTED);
    field.setType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
    field.setName("distinct"); //$NON-NLS-1$
    addFieldComment(field, "是否相异");
    topLevelClass.addField(field);

    // add field, getter, setter for orderby clause
    field = new Field();
    field.setVisibility(JavaVisibility.PROTECTED);
    field.setType(FullyQualifiedJavaType.getStringInstance());
    field.setName("orderByClause"); //$NON-NLS-1$
    addFieldComment(field, "排序字段");
    topLevelClass.addField(field);

    Method method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setConstructor(true);
    method.setName("Criteria"); //$NON-NLS-1$
    method.addBodyLine("condition = new HashMap<String, Object>();"); //$NON-NLS-1$
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("clear"); //$NON-NLS-1$
    method.addBodyLine("condition.clear();"); //$NON-NLS-1$
    method.addBodyLine("orderByClause = null;"); //$NON-NLS-1$
    method.addBodyLine("distinct = false;"); //$NON-NLS-1$
    method.addBodyLine("this.limit=null;"); //$NON-NLS-1$
    method.addBodyLine("this.start=null;"); //$NON-NLS-1$
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(criteria);
    method.setName("put"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "condition")); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getObjectInstance(), "value")); //$NON-NLS-1$
    method.addBodyLine("this.condition.put(condition, value);"); //$NON-NLS-1$
    method.addBodyLine("return (Criteria) this;"); //$NON-NLS-1$
    addSetterComment(method, OutputUtilities.lineSeparator+"\t *            查询的条件名称"+OutputUtilities.lineSeparator+"\t * @param value"+OutputUtilities.lineSeparator+"\t *            查询的值", "condition");
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setOrderByClause"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(), "orderByClause")); //$NON-NLS-1$
    method.addBodyLine("this.orderByClause = orderByClause;"); //$NON-NLS-1$
    addSetterComment(method, OutputUtilities.lineSeparator+"\t *            排序字段", "orderByClause");
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setDistinct"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getBooleanPrimitiveInstance(), "distinct")); //$NON-NLS-1$
    method.addBodyLine("this.distinct = distinct;"); //$NON-NLS-1$
    addSetterComment(method, OutputUtilities.lineSeparator+"\t *            是否相异", "distinct");
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setCondition"); //$NON-NLS-1$
    method.addParameter(new Parameter(types, "condition")); //$NON-NLS-1$
    method.addBodyLine("this.condition = condition;"); //$NON-NLS-1$
    method.addDeprecated();
    topLevelClass.addMethod(method);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setReturnType(types);
    method.setName("getCondition"); //$NON-NLS-1$
    method.addBodyLine("return condition;"); //$NON-NLS-1$
    method.addDeprecated();
    topLevelClass.addMethod(method);
    field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(FullyQualifiedJavaType.getInteger());
    field.setName("limit"); //$NON-NLS-1$
    topLevelClass.addField(field);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setLimit"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getInteger(), "limit")); //$NON-NLS-1$
    method.addBodyLine("this.limit = limit;"); //$NON-NLS-1$
    addSetterComment(method, "每页大小,即mysql中的length", "limit");
    topLevelClass.addMethod(method);

    field = new Field();
    field.setVisibility(JavaVisibility.PRIVATE);
    field.setType(FullyQualifiedJavaType.getInteger());
    field.setName("start"); //$NON-NLS-1$
    topLevelClass.addField(field);

    method = new Method();
    method.setVisibility(JavaVisibility.PUBLIC);
    method.setName("setStart"); //$NON-NLS-1$
    method.addParameter(new Parameter(FullyQualifiedJavaType.getInteger(), "start")); //$NON-NLS-1$
    method.addBodyLine("this.start = start;"); //$NON-NLS-1$
    addSetterComment(method, "开始行数,即mysql中的offset", "start");
    topLevelClass.addMethod(method);

    GeneratedJavaFile file = new GeneratedJavaFile(topLevelClass, context.getJavaModelGeneratorConfiguration()
        .getTargetProject());
    files.add(file);
    return files;
View Full Code Here

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

    pojoType = new FullyQualifiedJavaType(pojoUrl + "." + tableName);

    pojoCriteriaType = new FullyQualifiedJavaType(pojoUrl + "." + "Criteria");
    listType = new FullyQualifiedJavaType("java.util.List");
    Interface interface1 = new Interface(interfaceType);
    TopLevelClass topLevelClass = new TopLevelClass(serviceType);
    // 导入必要的类
    addImport(interface1, topLevelClass);

    // 接口
    addService(interface1, introspectedTable, tableName, files);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.