使用 dom4j.jar
public static void main(String[] args) throws Exception {
generateSql("D://mapper", "D://test.sql");
}
/**
* 生成sql * @param dirPath mapper.xml的父级文件夹 * @param sqlFile 选择你将要生成sql的文件 * @throws IOException
*/
private static void generateSql(String dirPath, String sqlFile) throws IOException {
FileWriter fw = null;
try {
File dir = new File(dirPath);
File sql = new File(sqlFile);
if (sql.exists()) {
sql.delete();
}
sql.createNewFile();
fw = new FileWriter(sql);
if (dir.exists() && dir.isDirectory()) {
File[] files = dir.listFiles();
for (File file : files) {
if (file.isFile() && file.getName().endsWith(".xml")) {
System.out.println(file.getName());
fw.append("\r\n");