<i><%@page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'Goods.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<link rel="stylesheet"
href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
<script
src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/angularjs.js"></script>
<script type="text/javascript" src="js/jquery-2.1.0.js"></script>
<script type="text/javascript">
var app = angular.module("myapp", []);
//进来就查询所有商品
app.controller("myController", function($scope, $http) {
$http.post("GoodsController/findGoods").success(function(obj) {
$scope.product = obj;
});
//点击加的按钮减1
$scope.jia = function(index) {
var id = $scope.product[index].id;
$http.post("GoodsController/jia?id=" + id).success(
++$scope.product[index].account);
};
//点击减的按钮减1
$scope.jian = function(index) {
var id = $scope.product[index].id;
var account = $scope.product[index].account;
if (account > 1) {
$http.post("GoodsController/jian?id=" + id).success(
--$scope.product[index].account);
} else {
if (confirm("确认删除?")) {
$http.post("GoodsController/Del?id=" + id).success(
function() {
alert("删除成功");
location.reload();
});
}
}
};
//点击删除的按钮删除
$scope.del = function(index) {
var id = $scope.product[index].id;
if (confirm("确认删除?")) {
$http.post("GoodsController/Del?id=" + id).success(function() {
alert("删除成功");
location.reload();
});
}
};
$scope.update = function(index) {
var id = $scope.product[index].id;
var account = $scope.product[index].account;
alert(id);
alert(account);
$http.post("GoodsController/updateGoods?id=" + id + "&account="
+ account);
};
});
function sub() {
var arr = [];
var uid = ${nameid}
$(":checked").each(function() {
arr.push($(this).val());
});
alert(arr.length);
if (arr.length < 1) {
alert("请至少选中一件物品!");
return false;
} else {
$.post("OrderController/addOrder", {
"gid" : arr.join(","),
"uid" : uid
}, function(da) {
if (da == "ok") {
alert("发送成功!");
} else {
alert("发送失败!");
}
}, "json");
}
}
</script>
</head>
<body ng-app="myapp">
<div class="container" ng-controller="myController">
<h1>欢迎进入购物车</h1>
<table>
<tr>
<td><input type="checkbox" ng-model="all"></td>
<td>商品编号</td>
<td>商品名称</td>
<td>商品价格</td>
<td>购买数量</td>
<td>操作</td>
</tr>
<tr ng-repeat="p in product">
<td><input type="checkbox" value="{{p.id}}" ng-checked="all"
value="{{p.id}}" class="fxk"></td>
<td>{{p.id}}</td>
<td>{{p.goodsname}}</td>
<td>{{p.price}}</td>
<td>
<button class=" btn btn-success" value="{{p.id}}"
ng-click="jia($index)">+</button>
<input type="text"
ng-model="p.account" style="width: 30" value="{{p.account}}"
ng-blur="update($index)" class="account">
<button class="btn btn-success" value="{{p.id}}"
ng-click="jian($index)">-</button>
</td>
<td><button class=" btn " ng-click="del($index)">删除</button></td>
</tr>
<tr>
<td><button class=" btn btn-success" οnclick="sub()">购买</button></td>
</tr>
</table>
</div>
</body>
</html> </i>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'Goods.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<link rel="stylesheet"
href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
<script
src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/angularjs.js"></script>
<script type="text/javascript" src="js/jquery-2.1.0.js"></script>
<script type="text/javascript">
var app = angular.module("myapp", []);
//进来就查询所有商品
app.controller("myController", function($scope, $http) {
$http.post("GoodsController/findGoods").success(function(obj) {
$scope.product = obj;
});
//点击加的按钮减1
$scope.jia = function(index) {
var id = $scope.product[index].id;
$http.post("GoodsController/jia?id=" + id).success(
++$scope.product[index].account);
};
//点击减的按钮减1
$scope.jian = function(index) {
var id = $scope.product[index].id;
var account = $scope.product[index].account;
if (account > 1) {
$http.post("GoodsController/jian?id=" + id).success(
--$scope.product[index].account);
} else {
if (confirm("确认删除?")) {
$http.post("GoodsController/Del?id=" + id).success(
function() {
alert("删除成功");
location.reload();
});
}
}
};
//点击删除的按钮删除
$scope.del = function(index) {
var id = $scope.product[index].id;
if (confirm("确认删除?")) {
$http.post("GoodsController/Del?id=" + id).success(function() {
alert("删除成功");
location.reload();
});
}
};
$scope.update = function(index) {
var id = $scope.product[index].id;
var account = $scope.product[index].account;
alert(id);
alert(account);
$http.post("GoodsController/updateGoods?id=" + id + "&account="
+ account);
};
});
function sub() {
var arr = [];
var uid = ${nameid}
$(":checked").each(function() {
arr.push($(this).val());
});
alert(arr.length);
if (arr.length < 1) {
alert("请至少选中一件物品!");
return false;
} else {
$.post("OrderController/addOrder", {
"gid" : arr.join(","),
"uid" : uid
}, function(da) {
if (da == "ok") {
alert("发送成功!");
} else {
alert("发送失败!");
}
}, "json");
}
}
</script>
</head>
<body ng-app="myapp">
<div class="container" ng-controller="myController">
<h1>欢迎进入购物车</h1>
<table>
<tr>
<td><input type="checkbox" ng-model="all"></td>
<td>商品编号</td>
<td>商品名称</td>
<td>商品价格</td>
<td>购买数量</td>
<td>操作</td>
</tr>
<tr ng-repeat="p in product">
<td><input type="checkbox" value="{{p.id}}" ng-checked="all"
value="{{p.id}}" class="fxk"></td>
<td>{{p.id}}</td>
<td>{{p.goodsname}}</td>
<td>{{p.price}}</td>
<td>
<button class=" btn btn-success" value="{{p.id}}"
ng-click="jia($index)">+</button>
<input type="text"
ng-model="p.account" style="width: 30" value="{{p.account}}"
ng-blur="update($index)" class="account">
<button class="btn btn-success" value="{{p.id}}"
ng-click="jian($index)">-</button>
</td>
<td><button class=" btn " ng-click="del($index)">删除</button></td>
</tr>
<tr>
<td><button class=" btn btn-success" οnclick="sub()">购买</button></td>
</tr>
</table>
</div>
</body>
</html> </i>