Java Code Examples for org.mybatis.generator.internal.util.StringUtility#stringHasValue()

The following examples show how to use org.mybatis.generator.internal.util.StringUtility#stringHasValue() . 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: CommentGenerator.java    From mall-learning with Apache License 2.0 6 votes vote down vote up
/**
     * 给字段添加注释
     */
    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                                IntrospectedColumn introspectedColumn) {
        String remarks = introspectedColumn.getRemarks();
        //根据参数和备注信息判断是否添加备注信息
        if(addRemarkComments&&StringUtility.stringHasValue(remarks)){
//            addFieldJavaDoc(field, remarks);
            //数据库中特殊字符需要转义
            if(remarks.contains("\"")){
                remarks = remarks.replace("\"","'");
            }
            //给model的字段添加swagger注解
            field.addJavaDocLine("@ApiModelProperty(value = \""+remarks+"\")");
        }
    }
 
Example 2
Source File: SqlScriptRunner.java    From dolphin with Apache License 2.0 6 votes vote down vote up
public SqlScriptRunner(String sourceFile, String driver, String url,
        String userId, String password) throws MojoExecutionException {
    
    if (!StringUtility.stringHasValue(sourceFile)) {
        throw new MojoExecutionException("SQL script file is required");
    }
    
    if (!StringUtility.stringHasValue(driver)) {
        throw new MojoExecutionException("JDBC Driver is required");
    }
    
    if (!StringUtility.stringHasValue(url)) {
        throw new MojoExecutionException("JDBC URL is required");
    }
    
    this.sourceFile = sourceFile;
    this.driver = driver;
    this.url = url;
    this.userid = userId;
    this.password = password;
}
 
Example 3
Source File: EnumTypeStatusPlugin.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 解析注释
 * @param remarks
 */
public void parseRemarks(String remarks) throws CannotParseException {
    if (!StringUtility.stringHasValue(remarks) || !remarks.matches(REMARKS_PATTERN)) {
        throw new CannotParseException();
    } else {
        // 提取信息
        Pattern pattern = Pattern.compile(NEED_PATTERN);
        Matcher matcher = pattern.matcher(remarks);
        if (matcher.find() && matcher.groupCount() == 2) {
            String enumInfoStr = matcher.group(1);
            // 根据逗号切分
            String[] enumInfoStrs = enumInfoStr.split(",");

            // 提取每个节点信息
            for (String enumInfoItemStr : enumInfoStrs) {
                pattern = Pattern.compile(ITEM_PATTERN);
                matcher = pattern.matcher(enumInfoItemStr.trim());
                if (matcher.find() && matcher.groupCount() == 3) {
                    this.addItem(matcher.group(1), matcher.group(3), matcher.group(2));
                }
            }
        }
    }
}
 
Example 4
Source File: GenCommentGenerator.java    From scaffold-cloud with MIT License 6 votes vote down vote up
/**
 * setter方法注释
 * @param method
 * @param introspectedTable
 * @param introspectedColumn
 */
@Override
public void addSetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
	StringBuilder sb = new StringBuilder();
	method.addJavaDocLine("/**");
	if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) {
		sb.append(" * 设置");
		sb.append(introspectedColumn.getRemarks());
		method.addJavaDocLine(sb.toString());
		method.addJavaDocLine(" *");
	}
	Parameter parm = method.getParameters().get(0);
	sb.setLength(0);
	sb.append(" * @param ");
	sb.append(parm.getName());
	if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) {
		sb.append(" ");
		sb.append(introspectedColumn.getRemarks());
	}
	method.addJavaDocLine(sb.toString());
	method.addJavaDocLine(" */");
}
 
Example 5
Source File: CommentGenerator.java    From mall-swarm with Apache License 2.0 6 votes vote down vote up
/**
     * 给字段添加注释
     */
    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                                IntrospectedColumn introspectedColumn) {
        String remarks = introspectedColumn.getRemarks();
        //根据参数和备注信息判断是否添加备注信息
        if(addRemarkComments&&StringUtility.stringHasValue(remarks)){
//            addFieldJavaDoc(field, remarks);
            //数据库中特殊字符需要转义
            if(remarks.contains("\"")){
                remarks = remarks.replace("\"","'");
            }
            //给model的字段添加swagger注解
            field.addJavaDocLine("@ApiModelProperty(value = \""+remarks+"\")");
        }
    }
 
Example 6
Source File: CommentGenerator.java    From macrozheng-mall with MIT License 6 votes vote down vote up
/**
 * 给字段添加注释
 */
@Override
public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                            IntrospectedColumn introspectedColumn) {
    String remarks = introspectedColumn.getRemarks();
    //根据参数和备注信息判断是否添加备注信息
    if(addRemarkComments&&StringUtility.stringHasValue(remarks)){
        //文档注释开始
        field.addJavaDocLine("/**");
        //获取数据库字段的备注信息
        String[] remarkLines = remarks.split(System.getProperty("line.separator"));
        for(String remarkLine:remarkLines){
            field.addJavaDocLine(" * "+remarkLine);
        }
        addJavadocTag(field, false);
        field.addJavaDocLine(" */");
    }
}
 
Example 7
Source File: CommentGenerator.java    From mall-learning with Apache License 2.0 6 votes vote down vote up
/**
     * 给字段添加注释
     */
    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                                IntrospectedColumn introspectedColumn) {
        String remarks = introspectedColumn.getRemarks();
        //根据参数和备注信息判断是否添加备注信息
        if(addRemarkComments&&StringUtility.stringHasValue(remarks)){
//            addFieldJavaDoc(field, remarks);
            //数据库中特殊字符需要转义
            if(remarks.contains("\"")){
                remarks = remarks.replace("\"","'");
            }
            //给model的字段添加swagger注解
            field.addJavaDocLine("@ApiModelProperty(value = \""+remarks+"\")");
        }
    }
 
Example 8
Source File: CommentGenerator.java    From HIS with Apache License 2.0 6 votes vote down vote up
/**
     * 给字段添加注释
     */
    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                                IntrospectedColumn introspectedColumn) {
        String remarks = introspectedColumn.getRemarks();
        //根据参数和备注信息判断是否添加备注信息
        if(addRemarkComments&&StringUtility.stringHasValue(remarks)){
//            addFieldJavaDoc(field, remarks);
            //数据库中特殊字符需要转义
            if(remarks.contains("\"")){
                remarks = remarks.replace("\"","'");
            }
            //给model的字段添加swagger注解
            field.addJavaDocLine("@ApiModelProperty(value = \""+remarks+"\")");
        }
    }
 
Example 9
Source File: CommentGenerator.java    From HIS with Apache License 2.0 6 votes vote down vote up
/**
     * 给字段添加注释
     */
    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                                IntrospectedColumn introspectedColumn) {
        String remarks = introspectedColumn.getRemarks();
        //根据参数和备注信息判断是否添加备注信息
        if(addRemarkComments&&StringUtility.stringHasValue(remarks)){
//            addFieldJavaDoc(field, remarks);
            //数据库中特殊字符需要转义
            if(remarks.contains("\"")){
                remarks = remarks.replace("\"","'");
            }
            //给model的字段添加swagger注解
            field.addJavaDocLine("@ApiModelProperty(value = \""+remarks+"\")");
        }
    }
 
Example 10
Source File: TemplateCommentGenerator.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 添加评论
 * @param xmlElement
 * @param map
 * @param node
 */
private void addXmlElementComment(XmlElement xmlElement, Map<String, Object> map, EnumNode node) {
    if (this.suppressAllComments) {
        return;
    }
    // 获取评论
    String[] comments = getComments(map, node);
    if (comments != null) {
        // 去除空评论
        if (comments.length == 1 && !StringUtility.stringHasValue(comments[0])) {
            return;
        }
        // 添加评论
        for (String comment : comments) {
            xmlElement.addElement(new TextElement(comment));
        }
    }
}
 
Example 11
Source File: CommentGenerator.java    From HIS with Apache License 2.0 6 votes vote down vote up
/**
     * 给字段添加注释
     */
    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                                IntrospectedColumn introspectedColumn) {
        String remarks = introspectedColumn.getRemarks();
        //根据参数和备注信息判断是否添加备注信息
        if(addRemarkComments&&StringUtility.stringHasValue(remarks)){
//            addFieldJavaDoc(field, remarks);
            //数据库中特殊字符需要转义
            if(remarks.contains("\"")){
                remarks = remarks.replace("\"","'");
            }
            //给model的字段添加swagger注解
            field.addJavaDocLine("@ApiModelProperty(value = \""+remarks+"\")");
        }
    }
 
Example 12
Source File: CommentGenerator.java    From mall-learning with Apache License 2.0 6 votes vote down vote up
/**
     * 给字段添加注释
     */
    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                                IntrospectedColumn introspectedColumn) {
        String remarks = introspectedColumn.getRemarks();
        //根据参数和备注信息判断是否添加备注信息
        if(addRemarkComments&&StringUtility.stringHasValue(remarks)){
//            addFieldJavaDoc(field, remarks);
            //数据库中特殊字符需要转义
            if(remarks.contains("\"")){
                remarks = remarks.replace("\"","'");
            }
            //给model的字段添加swagger注解
            field.addJavaDocLine("@ApiModelProperty(value = \""+remarks+"\")");
        }
    }
 
Example 13
Source File: CommentGenerator.java    From server with MIT License 6 votes vote down vote up
/**
 * 给字段添加注释
 */
@Override
public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                            IntrospectedColumn introspectedColumn) {
    String remarks = introspectedColumn.getRemarks();
    //根据参数和备注信息判断是否添加备注信息
    if(addRemarkComments&&StringUtility.stringHasValue(remarks)){
        //文档注释开始
        field.addJavaDocLine("/**");
        //获取数据库字段的备注信息
        String[] remarkLines = remarks.split(System.getProperty("line.separator"));
        for(String remarkLine:remarkLines){
            field.addJavaDocLine(" * "+remarkLine);
        }
        addJavadocTag(field, false);
        field.addJavaDocLine(" */");
    }
}
 
Example 14
Source File: SqlScriptRunner.java    From dolphin with Apache License 2.0 5 votes vote down vote up
private String readStatement(BufferedReader br) throws IOException {
    StringBuffer sb = new StringBuffer();

    String line;

    while ((line = br.readLine()) != null) {
        if (line.startsWith("--")) { //$NON-NLS-1$
            continue;
        }

        if (!StringUtility.stringHasValue(line)) {
            continue;
        }

        if (line.endsWith(";")) { //$NON-NLS-1$
            sb.append(line.substring(0, line.length() - 1));
            break;
        } else {
            sb.append(' ');
            sb.append(line);
        }
    }

    String s = sb.toString().trim();

    if (s.length() > 0) {
        log.debug((Messages.getString("Progress.13", s))); //$NON-NLS-1$
    }

    return s.length() > 0 ? s : null;
}
 
Example 15
Source File: DefaultCommentGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public void addModelClassComment(TopLevelClass topLevelClass,
        IntrospectedTable introspectedTable) {
    if (suppressAllComments  || !addRemarkComments) {
        return;
    }

    topLevelClass.addJavaDocLine("/**");

    String remarks = introspectedTable.getRemarks();
    if (addRemarkComments && StringUtility.stringHasValue(remarks)) {
        topLevelClass.addJavaDocLine(" * Database Table Remarks:");
        String[] remarkLines = remarks.split(System.getProperty("line.separator")); 
        for (String remarkLine : remarkLines) {
            topLevelClass.addJavaDocLine(" *   " + remarkLine); 
        }
    }
    topLevelClass.addJavaDocLine(" *");

    topLevelClass
            .addJavaDocLine(" * This class was generated by MyBatis Generator.");

    StringBuilder sb = new StringBuilder();
    sb.append(" * This class corresponds to the database table ");
    sb.append(introspectedTable.getFullyQualifiedTable());
    topLevelClass.addJavaDocLine(sb.toString());

    topLevelClass.addJavaDocLine(" */");
}
 
Example 16
Source File: ExampleExtendsPlugin.java    From S-mall-ssm with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setProperties(Properties properties) {
    super.setProperties(properties);
    String example = this.properties.getProperty("example");
    if (StringUtility.stringHasValue(example)) {
        this.example = example;
    } else {
        throw new RuntimeException("example插件缺少必要的example属性!");
    }
}
 
Example 17
Source File: DefaultCommentGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public void addModelClassComment(TopLevelClass topLevelClass,
                                 IntrospectedTable introspectedTable) {
    if (suppressAllComments || !addRemarkComments) {
        return;
    }

    StringBuilder sb = new StringBuilder();

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

    String remarks = introspectedTable.getRemarks();
    if (addRemarkComments && StringUtility.stringHasValue(remarks)) {
        topLevelClass.addJavaDocLine(" * Database Table Remarks:");
        String[] remarkLines = remarks.split(System.getProperty("line.separator"));  //$NON-NLS-1$
        for (String remarkLine : remarkLines) {
            topLevelClass.addJavaDocLine(" *   " + remarkLine);  //$NON-NLS-1$
        }
    }
    topLevelClass.addJavaDocLine(" *"); //$NON-NLS-1$

    topLevelClass
            .addJavaDocLine(" * This class was generated by MyBatis Generator."); //$NON-NLS-1$

    sb.append(" * This class corresponds to the database table "); //$NON-NLS-1$
    sb.append(introspectedTable.getFullyQualifiedTable());
    topLevelClass.addJavaDocLine(sb.toString());

    addJavadocTag(topLevelClass, true);

    topLevelClass.addJavaDocLine(" */"); //$NON-NLS-1$
}
 
Example 18
Source File: MapperExtendsPlugin.java    From S-mall-ssm with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setProperties(Properties properties) {
    super.setProperties(properties);
    String mappers = this.properties.getProperty("mappers");
    if (StringUtility.stringHasValue(mappers)) {
        for (String mapper : mappers.split(",")) {
            this.mappers.add(mapper);
        }
    } else {
        throw new RuntimeException("Mapper插件缺少必要的mappers属性!");
    }
}
 
Example 19
Source File: BasePlugin.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean validate(List<String> warnings) {
    this.warnings = warnings;
    // 插件使用前提是targetRuntime为MyBatis3
    if (StringUtility.stringHasValue(getContext().getTargetRuntime()) && "MyBatis3".equalsIgnoreCase(getContext().getTargetRuntime()) == false) {
        warnings.add("itfsw:插件" + this.getClass().getTypeName() + "要求运行targetRuntime必须为MyBatis3!");
        return false;
    }

    return true;
}
 
Example 20
Source File: SimpleSelectAllElementGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 4 votes vote down vote up
@Override
public void addElements(XmlElement parentElement) {
    XmlElement answer = new XmlElement("select"); //$NON-NLS-1$

    answer.addAttribute(new Attribute(
            "id", introspectedTable.getSelectAllStatementId())); //$NON-NLS-1$
    answer.addAttribute(new Attribute("resultMap", //$NON-NLS-1$
            introspectedTable.getBaseResultMapId()));

    context.getCommentGenerator().addComment(answer);

    StringBuilder sb = new StringBuilder();
    sb.append("select "); //$NON-NLS-1$
    Iterator<IntrospectedColumn> iter = introspectedTable.getAllColumns()
            .iterator();
    while (iter.hasNext()) {
        sb.append(MyBatis3FormattingUtilities.getSelectListPhrase(iter
                .next()));

        if (iter.hasNext()) {
            sb.append(", "); //$NON-NLS-1$
        }

        if (sb.length() > 80) {
            answer.addElement(new TextElement(sb.toString()));
            sb.setLength(0);
        }
    }

    if (sb.length() > 0) {
        answer.addElement((new TextElement(sb.toString())));
    }

    sb.setLength(0);
    sb.append("from "); //$NON-NLS-1$
    sb.append(introspectedTable
            .getAliasedFullyQualifiedTableNameAtRuntime());
    answer.addElement(new TextElement(sb.toString()));
    
    String orderByClause = introspectedTable.getTableConfigurationProperty(PropertyRegistry.TABLE_SELECT_ALL_ORDER_BY_CLAUSE);
    boolean hasOrderBy = StringUtility.stringHasValue(orderByClause);
    if (hasOrderBy) {
        sb.setLength(0);
        sb.append("order by "); //$NON-NLS-1$
        sb.append(orderByClause);
        answer.addElement(new TextElement(sb.toString()));
    }

    if (context.getPlugins().sqlMapSelectAllElementGenerated(
            answer, introspectedTable)) {
        parentElement.addElement(answer);
    }
}