matrix.business.common.utils.SqlUtil Maven / Gradle / Ivy
package matrix.business.common.utils;
import matrix.boot.common.exception.ServiceException;
import matrix.boot.common.utils.BIOStreamUtil;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
/**
* sql工具,获取资源下配置的sql
* @author wangcheng
* 2021/8/26
**/
public class SqlUtil {
/**
* 获取sql
*
* @param fileName 文件名称
* @return sql文件
*/
public static String getSql(String fileName) {
InputStream is = null;
try {
is = new PathMatchingResourcePatternResolver().getResource("business-sql/" + fileName).getInputStream();
return " " + BIOStreamUtil.streamToString(is) + " ";
} catch (Exception e) {
throw new ServiceException(e);
} finally {
BIOStreamUtil.closeStream(is);
}
}
/**
* 获取占位符数组
* @param size 数量
* @return 占位符数组
*/
public static List getPlaceholder(int size) {
List placeholderList = new ArrayList<>();
for (int i = 0; i < size; i++) {
placeholderList.add("?");
}
return placeholderList;
}
}