30 Star 85 Fork 18

drinkjava2 / GoSqlGo

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
Clone or download
demo1.html 2.87 KB
Copy Edit Web IDE Raw Blame History
drinkjava2 authored 2019-05-14 08:03 . node.js done, randomId cache done
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
section {
margin-bottom: 30px
}
section header {
font-weight: bolder;
padding-bottom: 10px;
}
.amount {
width: 200px;
text-align: right;
border: 1px solid #aaa;
background-color: #eee;
padding: 3px 8px;
}
.msg {
width: 80%;
padding: 8px;
margin-bottom: 20px;
}
</style>
<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>
<script>
document.write($java(`return new WebBox("/page/menu.html").setAttribute("title", $1);`, "Transaction demo, use jQuery"));
function getUserListHtml(){
var users=$$qryMapList(`select * from account where amount>=? order by id`,0);
var html="User List:<br/>";
for(var i=0;i<users.length;i++)
html+="User ID:" + users[i].ID+", AMOUNT:"+ users[i].AMOUNT+"<br/>";
return html;
}
</script>
<div id="msgid" class="msg"></div>
<p id="Users">
<script>document.write(getUserListHtml());</script>
</p>
<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($$qryEntity(`com.demo.entity.Account, select * from account where id=?`, 'B').amount);
</script>
</div>
</section>
<script>
function transfer(from, to, money){
var rst = $javaTx(`#TransferMoney
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 "Error: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.indexOf("Transfer Success!")==0) {
var words=rst.split('|');
$("#msgid").text(words[0]);
$("#"+from).text(words[1]);
$("#"+to).text(words[2]);
$("#msgid").css("background", "#dfb");
$("#Users").html(getUserListHtml());
}
else if(rst.indexOf("Error:")==0) {
$("#msgid").text(rst.substring(6));
$("#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>

Comment ( 0 )

Sign in for post a comment

Java
1
https://gitee.com/drinkjava2/gosqlgo.git
git@gitee.com:drinkjava2/gosqlgo.git
drinkjava2
gosqlgo
GoSqlGo
master

Search