之前接了个特别的任务,要把项目里所有的sql查询要改成在代码中执行。。。。为了避免下次又遇到类似的特殊任务,先记下来。
方法也很简单:把mybatis中的代码复制到文件中,读取然后格式化即可
public class RedText { public static StringBuffer red(String filePath) { StringBuffer fileinfo = new StringBuffer(); try { InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(filePath), "utf-8"); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String lineText = null; int count = 0; while ((lineText = bufferedReader.readLine()) != null) { String[] line = lineText.split(" AS"); for (int i = 0; i < line.length; i++) { StringBuffer linbf = new StringBuffer(); if (i == 0) { linbf.append(line[i]); if (count == 0) { linbf.insert(0, """); } else { linbf.insert(0, "","); } linbf.insert(linbf.length(), " AS"+ "); } else { linbf.append(line[i].replace(",", "").replace("\", "")); linbf.insert(1, ""\"); linbf.insert(linbf.length()-1, "\"); linbf.insert(linbf.length(), ""+"); } count += 1; fileinfo.append(linbf); } } bufferedReader.close(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return fileinfo; } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)