亲宝软件园·资讯

展开

javascript制作sql转换为stringBuffer的小工具

人气:0

sql转换为stringBuffer的小工具,dao层拼接sql很麻烦,用这个小工具可以快速拼接,把写好的sql在sql工具中格式化好,然后复制进去就可以了

演示地址:http://runjs.cnhttps://img.qb5200.com/download-x/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>

以上所述就是本文的全部内容了,希望大家能够喜欢。

加载全部内容

相关教程
猜你喜欢
用户评论