private String replaceChoose(SqlObject sqlObj, Map<String, Object> parameters) {
		String query = null;
		if (sqlObj != null) {
			query = sqlObj.getValue();
			if (StringUtils.isNotEmpty(query)) {

				try {
					// 执行子句构建 子句格式为{statement}
					List<Choose> chooseList = sqlObj.getChoose();

					if (chooseList != null && parameters != null) {
						for (Choose choose : chooseList) {
							String condition = choose.getWhen();
							if (parameters.containsKey(condition)) {
								String statement = choose.getBlock();

								// 如果不存在statement参数，则使用when参数代替
								if (StringUtils.isEmpty(statement)) {
									statement = condition;
								}
								statement = "{" + statement + "}";

								if (StringUtils.contains(query, statement)) {
									query = query.replace(statement, choose.getValue());
								} else {
									query = query + " " + choose.getValue();
								}
							}
						}
					}

					// 清理没有被替换的子句
					String regexs = "[{](\\w*)[}]"; // 子句替换模式
					Pattern regex = Pattern.compile(regexs);
					Matcher regexMatcher = regex.matcher(query);
					while (regexMatcher.find()) {
						query = query.replace(regexMatcher.group(0), "");
					}

				} catch (Exception e) {

				}
			}
		}

		return query;
	}
private String replaceChoose ( SqlObject sqlObj , Map < String , Object > parameters ) { String query = null ; if ( sqlObj != null ) { query = sqlObj . getValue ( ) ; if ( StringUtils . isNotEmpty ( query ) ) { try { List < Choose > chooseList = sqlObj . getChoose ( ) ; if ( chooseList != null && parameters != null ) { for ( Choose choose : chooseList ) { String condition = choose . getWhen ( ) ; if ( parameters . containsKey ( condition ) ) { String statement = choose . getBlock ( ) ; if ( StringUtils . isEmpty ( statement ) ) { statement = condition ; } statement = "{" + statement + "}" ; if ( StringUtils . contains ( query , statement ) ) { query = query . replace ( statement , choose . getValue ( ) ) ; } else { query = query + " " + choose . getValue ( ) ; } } } } String regexs = "[{](\\w*)[}]" ; Pattern regex = Pattern . compile ( regexs ) ; Matcher regexMatcher = regex . matcher ( query ) ; while ( regexMatcher . find ( ) ) { query = query . replace ( regexMatcher . group ( 0 ) , "" ) ; } } catch ( Exception e ) { } } } return query ; }
/*
替换SQL语句中的条件

@param sql 需要构建的SQL对象

@param parameters 参数表

@return 构建后的SQL语句