sql轉換為stringBuffer的小工具,dao層拼接sql很麻煩,用這個小工具可以快速拼接,把寫好的sql在sql工具中格式化好,然後複製進去就可以了
示範網址:http://runjs.cn/detail/fj14tpyu 有點醜,建議全螢幕查看,不過下載下來可以自己修改
代碼
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>change SQL</TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <script> var ie = !-[1,]; function changeSQL(){ var srcSQL = document.getElementById("srcSQL"); var srcInner = srcSQL.value; var sqlBuf = "sqlBuf" var BufObj = "StringBuffer sqlBuf = new StringBuffer();" var newSrc = ""; if(ie){ var newSrc = srcInner.split("\r\n"); }else{ var patt = new RegExp(/.+/g); var newSrc = srcInner.match(patt); } var len = newSrc.length; for(var i=0;i<len;i++){ var temp=newSrc[i]; if(i < len-1){ sqlBuf += ".append(\" " + temp + " \")" + "\r\n"; } if(i == len-1){ sqlBuf += ".append(\" " + temp + " \");"; } } var showSQL = document.getElementById("showSQL"); showSQL.innerText = BufObj + "\n" + sqlBuf; } </script> </HEAD> <BODY> <table border="1" width="100%" > <tr align="center"> <td width="45%"><textarea id="srcSQL" rows="40" cols="85" ></textarea></td> <td> <button onclick="changeSQL()" style="cursor:hand;"><font color="blue" size="5"><b>转换</b></button><p> </td> <td width="45%"><textarea id="showSQL" rows="40" cols="85" ></textarea></td> </tr> </table> </BODY> </HTML>
以上所述就是本文的全部內容了,希望大家能夠喜歡。