GoSqlGo 首个正式版发布,在前端写 SQL 和业务逻辑

栏目: 软件资讯 · 发布时间: 7年前

内容简介:GoSqlGo简介 | Description GoSqlGo是一个运行于后端的服务端工具,它的最大特点就是在开发期动态编译客户端Java代码,所有SQL和Java代码都可以在前端Html页面完成,业务开发可以不再依赖后端程序员了。 更新内容...

GoSqlGo简介 | Description

GoSqlGo是一个运行于后端的服务端工具,它的最大特点就是在开发期动态编译客户端 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片段,实测通过,完整文件位于这里
这是一个转账业务的演示,它把所有的业务逻辑都写在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

Apache 2.0

关注我 | About Me

Github
码云


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web Data Mining

Web Data Mining

Bing Liu / Springer / 2006-12-28 / USD 59.95

Web mining aims to discover useful information and knowledge from the Web hyperlink structure, page contents, and usage data. Although Web mining uses many conventional data mining techniques, it is n......一起来看看 《Web Data Mining》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具