GoSqlGo简介 | DescriptionGoSqlGo是一个运行于后端的服务端工具,它的最大特点就是在开发期动态编译客户端Java代码,所有SQL和Java代码都可以在前端Html页面完成,业务开发可以不再依赖后端程序员了。 更新内容: GoSqlGo1.0.0版为首个正式发行版,相比与上一个试验版,1.0.0版本完成了打包工具的开发,并已发布到Maven中央库。利用打包工具,html/Javascript中的SQL和Java代码,在布署阶段将会被抽取为类似$qry('CJKDn23r9','A',0)这样的根据ID来调用的语句,从而实现安全性。 关于GoSqlGo的打包工具使用和更多介绍,请详见码云项目主页 (https://gitee.com/drinkjava2/gosqlgo) 附:GoSqlGo前端使用示例 前端程序员可以直接在Javascript里写SQL和Java代码,例如以下为一个HTML片段,实测通过,完整文件位于这里。 <!DOCTYPE html>
<html>
<head>
<script src="/js/jquery-1.11.3.min.js"></script>
<script src="/js/jquery-ajax-ext.js"></script>
<script src="/js/gosqlgo.js"></script>
</head>
<body>
<h1>Transaction Demo</h1>
<div id="msgid" class="msg"></div>
<section>
<header>Account A</header>
<div id="A" class="amount">
<script>
document.write($qry('select amount from account where id=? and amount>=?', 'A',0));
</script>
</div>
</section>
<section>
<header>Account B</header>
<div id="B" class="amount">
<script>
document.write($qry('select amount from account where id=? and amount>=?', 'B',0));
</script>
</div>
</section>
<script>
function transfer(from, to, money){
var rst = $java(`TX
int money=Integer.parseInt($3);
if(money<=0)
throw new SecurityException("Money<=0, IP:"+ getRequest().getRemoteAddr());
Account a=new Account().setId($1).load();
if(a.getAmount()<money)
return "No enough balance!";
Account b=new Account().setId($2).load();
a.setAmount(a.getAmount()-money).update();
b.setAmount(b.getAmount()+money).update();
return "Transfer Success!|"+a.getAmount()+"|"+b.getAmount();
`, from,to,money
);
if(rst.startsWith("Transfer Success!")) {
var words=rst.split('|');
$("#msgid").text(words[0]);
$("#"+from).text(words[1]);
$("#"+to).text(words[2]);
$("#msgid").css("background", "#dfb");
}
else { $("#msgid").text(rst);
$("#msgid").css("background", "#ffbeb8");
}
}
</script>
<section>
<header>Transfer</header>
<form onsubmit="return false" action="##" method="post">
<input name="amount" value="100" class="amount">
<button name="btnA2B" value="true" onclick="transfer('A','B',100)">From
account A to account B</button>
<button name="btnB2A" value="true" onclick="transfer('B','A',100)">From
account B to account A</button>
</form>
</section>
</body>
</html>在布署阶段,可以用new DeployTool().goServ() 命令将上述html中的SQL和Java代码转移到服务端。已抽取出的Java类还可以用goFront()方法逆向操作,再将代码塞回到html中去。 作者其它开源项目 | Other Projects版权 | License关注我 | About MeGithub |