①修改工程pinyougou02-manager-web的specification.html文件
一、将parent工程install 一下,然后先将service工程跑起来,再将web工程跑起来,看看静态原型在容器里的运行情况。
二、引入相关js文件
<script type="text/javascript" src="../plugins/angularjs/angular.min.js"></script>
<!-- 分页组件开始 -->
<script type="text/javascript" src="../plugins/angularjs/pagination.js"></script>
<link rel="stylesheet" href="../plugins/angularjs/pagination.css">
<!-- 分页组件结束 -->
<script type="text/javascript" src="../js/base_pagination.js"></script>
<script type="text/javascript" src="../js/render_finish.js"></script>
<script type="text/javascript" src="../js/service/specificationService.js"></script>
<script type="text/javascript" src="../js/controller/baseController.js"></script>
<script type="text/javascript" src="../js/controller/specificationController.js"></script>
<!-- 删除以下内容
<script type="text/javascript">
var app = angular.module('pinyougou',['pagination']);//在js里可以用单引也可以用双引
app.directive('onFinishRenderFilters', function ($timeout) {
return {
restrict: 'A',
link: function(scope, element, attr) {
if (scope.$last === true) {
$timeout(function() {
scope.$emit('ngRepeatFinished');
});
}
}
};
});
//app为模块对象,控制器有控制器的名字,服务也要有服务的名字。
//和控制器一样也是有function并且可以接受参数和内容。
//品牌服务
app.service("brandService",function($http){
//不能用$scope,要用this,这是他本身。
this.findAll = function(){
//.success后面的内容,$scope.list = response;给了视图
//与视图交互,又与后端交互
//.success后面的内容是控制层的内容。
//所以只写前面的内容$http.get('../brand/findAll.do');
return $http.get('../brand/findAll.do');
}
this.findPage = function(entity08){
return $http.post('../brand/findPage.do',entity08);
}
this.findOne = function(entity09){
return $http.post("../brand/findOne.do",entity09);
}
this.add = function(entity06){
return $http.post('../brand/add.do', entity06);
}
this.update = function(entity07){
return $http.post('../brand/update.do', entity07);
}
this.dele = function(entity10){
return $http.post('../brand/delete.do',entity10);
}
this.search = function(entity11){
return $http.post("../brand/search.do",entity11);
}
});
app.controller('brandController',function($scope,$http,brandService){
$scope.$on('ngRepeatFinished', function(){
//可执行DOM操作
for(var i=0;i< $scope.selectIds.length;i++){
for(var j=0;j<$scope.list.length;j++){
if( $scope.list[j].id == $scope.selectIds[i]){
//在渲染 完成后,对复选框的 显示进行更新,false表示不勾选,true表示勾选
document.getElementById(String($scope.list[j].id)).checked = $scope.boxes[$scope.list[j].id];
}
}}
});
//查询品牌列表数据
$scope.findAll = function(){
//之前的访问json的路径是http://localhost:9101/brand/findAll.do
//则现在,在brand.html文件../返回根目录,webapp根目录,再寻找/brand/findAll.do
brandService.findAll().success(
function(response){
$scope.list = response;
}
);
}
$scope.paginationConf = {
//当前页
currentPage : 1,
//总记录数
totalItems : 10,
//每页记录数
itemsPerPage : 10,
//分页选项,下拉菜单
perPageOptions : [ 10, 20, 30, 40, 50 ],
//当页码重新变更后自动触发的方法
onChange : function() {
$scope.reloadList();
}};
//这个前端的方法名称findPage不一定要和后端的findPage方法名称一样,可以随意取
//只不过去一样的名称好辨别一些。
//分页
$scope.findPage = function(){
$scope.entity02 = {
pageNum: $scope.paginationConf.currentPage,
sizeNum: $scope.paginationConf.itemsPerPage
};
brandService.findPage($scope.entity02).success(
function(response){
//显示当前一页的[{},{},...{}]内容
$scope.list = response.rows;
//更改更新总记录数,更改此变量值,前端分页控件
//自动获得值
$scope.paginationConf.totalItems = response.total;
}
);
}
$scope.reloadList = function(){
//$scope.findPage();
$scope.search();//否则又会还原成全部的数据呈现
}
//保存
$scope.save = function(){
var object = null;
if($scope.entity.id != null){
object = brandService.update($scope.entity);
}else{
object = brandService.add($scope.entity);
}
object.success(
function(response){
if(response.success){
$scope.reloadList();//刷新
}else{
alert(response.message);
}
}
);
}
$scope.findOne = function($event){
$scope.entity03= {id: $event.target.parentNode.parentNode.children[1].innerText}
brandService.findOne($scope.entity03).success(
function(response){
$scope.entity = response;
}
);
}
$scope.selectIds = [];//用户勾选的ID集合
$scope.boxes = [];//保存复选框被选的状态,true(勾选)或者false(不勾选)
$scope.updateSelectIds = function($event,id){
if($event.target.checked){
$scope.selectIds.push(id);//push向集合添加元素
}else{
var index = $scope.selectIds.indexOf(id);//查找id值在集合中的位置
if(index != -1){
$scope.selectIds.splice(index,1);//从某个位置移掉几个元素
}
}
$scope.saveStatus();
}
//保存CheckBox复选框的true和false的状态
$scope.saveStatus = function(){
for(var j=0;j<$scope.list.length;j++){
for(var i=0;i< $scope.selectIds.length;i++){
//从第0位查找id为$scope.list[j].id的值,是否有这个id在$scope.selectIds里
if($scope.selectIds.indexOf($scope.list[j].id,0)!=-1){
$scope.boxes[$scope.list[j].id] = true;
}else{
$scope.boxes[$scope.list[j].id]= false;
}
}
}
}
$scope.dele = function(){
$scope.entity04=[];
for(var i=0;i<$scope.selectIds.length;i++){
$scope.entity04.push({id: $scope.selectIds[i]}) ;
}
brandService.dele($scope.entity04).success(
function(response){
for(var i=0;i<$scope.selectIds.length;i++){
//查找id值在集合中的位置
var index = $scope.selectIds.indexOf($scope.selectIds[i]);
if(index != -1){
$scope.selectIds.splice(index,1);//从某个位置移掉几个元素
}
}
if(response.success){
$scope.reloadList();
}else{
alert(response.message);
}
}
);
}
$scope.searchEntity = {};
//条件查询
$scope.search = function(){
$scope.entity05 = {
pageNum: $scope.paginationConf.currentPage,
sizeNum: $scope.paginationConf.itemsPerPage,
brand: $scope.searchEntity
};
brandService.search($scope.entity05).success(
function(response) {
$scope.list = response.rows;
$scope.paginationConf.totalItems = response.total;
}
)
}
});
</script>
-->
三、引入angularjs的指令和表达式
<body class="hold-transition skin-red sidebar-mini" ng-app="pinyougou" ng-controller="specificationController" >
<!--数据列表-->
<table id="dataList" class="table table-bordered table-striped table-hover dataTable">
<thead>
<tr>
<th class="" style="padding-right:0px">
<input id="selall" type="checkbox" class="icheckbox_square-blue">
</th>
<th class="sorting_asc">规格ID</th>
<th class="sorting">规格名称</th>
<th class="text-center">操作</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="entity in list" on-finish-render-filters>
<td><input type="checkbox" id="{{entity.id}}"
ng-click="updateSelectIds($event,entity.id)" /></td>
<td>{{entity.id}}</td>
<td>{{entity.specName}}</td>
<td class="text-center">
<button type="button" class="btn bg-olive btn-xs" data-toggle="modal" data-target="#editModal">修改</button>
</td>
</tr>
</tbody>
</table>
<!--数据列表/-->
四、放置分页组件
<tm-pagination conf="paginationConf" ></tm-pagination>
最后目前specification.html文件的内容为:
<!DOCTYPE html>
<html>
<head>
<!-- 页面meta -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>规格管理</title>
<meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
<link rel="stylesheet" href="../plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="../plugins/adminLTE/css/AdminLTE.css">
<link rel="stylesheet" href="../plugins/adminLTE/css/skins/_all-skins.min.css">
<link rel="stylesheet" href="../css/style.css">
<script src="../plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="../plugins/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../plugins/angularjs/angular.min.js"></script>
<!-- 分页组件开始 -->
<script type="text/javascript" src="../plugins/angularjs/pagination.js"></script>
<link rel="stylesheet" href="../plugins/angularjs/pagination.css">
<!-- 分页组件结束 -->
<script type="text/javascript" src="../js/base_pagination.js"></script>
<script type="text/javascript" src="../js/render_finish.js"></script>
<script type="text/javascript" src="../js/service/specificationService.js"></script>
<script type="text/javascript" src="../js/controller/baseController.js"></script>
<script type="text/javascript" src="../js/controller/specificationController.js"></script>
<!-- 删除以下内容
<script type="text/javascript">
var app = angular.module('pinyougou',['pagination']);//在js里可以用单引也可以用双引
app.directive('onFinishRenderFilters', function ($timeout) {
return {
restrict: 'A',
link: function(scope, element, attr) {
if (scope.$last === true) {
$timeout(function() {
scope.$emit('ngRepeatFinished');
});
}
}
};
});
//app为模块对象,控制器有控制器的名字,服务也要有服务的名字。
//和控制器一样也是有function并且可以接受参数和内容。
//品牌服务
app.service("brandService",function($http){
//不能用$scope,要用this,这是他本身。
this.findAll = function(){
//.success后面的内容,$scope.list = response;给了视图
//与视图交互,又与后端交互
//.success后面的内容是控制层的内容。
//所以只写前面的内容$http.get('../brand/findAll.do');
return $http.get('../brand/findAll.do');
}
this.findPage = function(entity08){
return $http.post('../brand/findPage.do',entity08);
}
this.findOne = function(entity09){
return $http.post("../brand/findOne.do",entity09);
}
this.add = function(entity06){
return $http.post('../brand/add.do', entity06);
}
this.update = function(entity07){
return $http.post('../brand/update.do', entity07);
}
this.dele = function(entity10){
return $http.post('../brand/delete.do',entity10);
}
this.search = function(entity11){
return $http.post("../brand/search.do",entity11);
}
});
app.controller('brandController',function($scope,$http,brandService){
$scope.$on('ngRepeatFinished', function(){
//可执行DOM操作
for(var i=0;i< $scope.selectIds.length;i++){
for(var j=0;j<$scope.list.length;j++){
if( $scope.list[j].id == $scope.selectIds[i]){
//在渲染 完成后,对复选框的 显示进行更新,false表示不勾选,true表示勾选
document.getElementById(String($scope.list[j].id)).checked = $scope.boxes[$scope.list[j].id];
}
}}
});
//查询品牌列表数据
$scope.findAll = function(){
//之前的访问json的路径是http://localhost:9101/brand/findAll.do
//则现在,在brand.html文件../返回根目录,webapp根目录,再寻找/brand/findAll.do
brandService.findAll().success(
function(response){
$scope.list = response;
}
);
}
$scope.paginationConf = {
//当前页
currentPage : 1,
//总记录数
totalItems : 10,
//每页记录数
itemsPerPage : 10,
//分页选项,下拉菜单
perPageOptions : [ 10, 20, 30, 40, 50 ],
//当页码重新变更后自动触发的方法
onChange : function() {
$scope.reloadList();
}};
//这个前端的方法名称findPage不一定要和后端的findPage方法名称一样,可以随意取
//只不过去一样的名称好辨别一些。
//分页
$scope.findPage = function(){
$scope.entity02 = {
pageNum: $scope.paginationConf.currentPage,
sizeNum: $scope.paginationConf.itemsPerPage
};
brandService.findPage($scope.entity02).success(
function(response){
//显示当前一页的[{},{},...{}]内容
$scope.list = response.rows;
//更改更新总记录数,更改此变量值,前端分页控件
//自动获得值
$scope.paginationConf.totalItems = response.total;
}
);
}
$scope.reloadList = function(){
//$scope.findPage();
$scope.search();//否则又会还原成全部的数据呈现
}
//保存
$scope.save = function(){
var object = null;
if($scope.entity.id != null){
object = brandService.update($scope.entity);
}else{
object = brandService.add($scope.entity);
}
object.success(
function(response){
if(response.success){
$scope.reloadList();//刷新
}else{
alert(response.message);
}
}
);
}
$scope.findOne = function($event){
$scope.entity03= {id: $event.target.parentNode.parentNode.children[1].innerText}
brandService.findOne($scope.entity03).success(
function(response){
$scope.entity = response;
}
);
}
$scope.selectIds = [];//用户勾选的ID集合
$scope.boxes = [];//保存复选框被选的状态,true(勾选)或者false(不勾选)
$scope.updateSelectIds = function($event,id){
if($event.target.checked){
$scope.selectIds.push(id);//push向集合添加元素
}else{
var index = $scope.selectIds.indexOf(id);//查找id值在集合中的位置
if(index != -1){
$scope.selectIds.splice(index,1);//从某个位置移掉几个元素
}
}
$scope.saveStatus();
}
//保存CheckBox复选框的true和false的状态
$scope.saveStatus = function(){
for(var j=0;j<$scope.list.length;j++){
for(var i=0;i< $scope.selectIds.length;i++){
//从第0位查找id为$scope.list[j].id的值,是否有这个id在$scope.selectIds里
if($scope.selectIds.indexOf($scope.list[j].id,0)!=-1){
$scope.boxes[$scope.list[j].id] = true;
}else{
$scope.boxes[$scope.list[j].id]= false;
}
}
}
}
$scope.dele = function(){
$scope.entity04=[];
for(var i=0;i<$scope.selectIds.length;i++){
$scope.entity04.push({id: $scope.selectIds[i]}) ;
}
brandService.dele($scope.entity04).success(
function(response){
for(var i=0;i<$scope.selectIds.length;i++){
//查找id值在集合中的位置
var index = $scope.selectIds.indexOf($scope.selectIds[i]);
if(index != -1){
$scope.selectIds.splice(index,1);//从某个位置移掉几个元素
}
}
if(response.success){
$scope.reloadList();
}else{
alert(response.message);
}
}
);
}
$scope.searchEntity = {};
//条件查询
$scope.search = function(){
$scope.entity05 = {
pageNum: $scope.paginationConf.currentPage,
sizeNum: $scope.paginationConf.itemsPerPage,
brand: $scope.searchEntity
};
brandService.search($scope.entity05).success(
function(response) {
$scope.list = response.rows;
$scope.paginationConf.totalItems = response.total;
}
)
}
});
</script>
-->
</head>
<body class="hold-transition skin-red sidebar-mini" ng-app="pinyougou" ng-controller="specificationController" >
<!-- .box-body -->
<div class="box-header with-border">
<h3 class="box-title">规格管理</h3>
</div>
<div class="box-body">
<!-- 数据表格 -->
<div class="table-box">
<!--工具栏-->
<div class="pull-left">
<div class="form-group form-inline">
<div class="btn-group">
<button type="button" class="btn btn-default" title="新建" data-toggle="modal" data-target="#editModal" ><i class="fa fa-file-o"></i> 新建</button>
<button type="button" class="btn btn-default" title="删除" ><i class="fa fa-trash-o"></i> 删除</button>
<button type="button" class="btn btn-default" title="刷新" onclick="window.location.reload();"><i class="fa fa-refresh"></i> 刷新</button>
</div>
</div>
</div>
<div class="box-tools pull-right">
<div class="has-feedback">
规格名称:<input >
<button class="btn btn-default" >查询</button>
</div>
</div>
<!--工具栏/-->
<!--数据列表-->
<table id="dataList" class="table table-bordered table-striped table-hover dataTable">
<thead>
<tr>
<th class="" style="padding-right:0px">
<input id="selall" type="checkbox" class="icheckbox_square-blue">
</th>
<th class="sorting_asc">规格ID</th>
<th class="sorting">规格名称</th>
<th class="text-center">操作</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="entity in list" on-finish-render-filters>
<td><input type="checkbox" id="{{entity.id}}"
ng-click="updateSelectIds($event,entity.id)" /></td>
<td>{{entity.id}}</td>
<td>{{entity.specName}}</td>
<td class="text-center">
<button type="button" class="btn bg-olive btn-xs" data-toggle="modal" data-target="#editModal">修改</button>
</td>
</tr>
</tbody>
</table>
<!--数据列表/-->
</div>
<!-- 数据表格 /-->
<tm-pagination conf="paginationConf" ></tm-pagination>
</div>
<!-- /.box-body -->
<!-- 编辑窗口 -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" >
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">规格编辑</h3>
</div>
<div class="modal-body">
<table class="table table-bordered table-striped" width="800px">
<tr>
<td>规格名称</td>
<td><input class="form-control" placeholder="规格名称" > </td>
</tr>
</table>
<!-- 规格选项 -->
<div class="btn-group">
<button type="button" class="btn btn-default" title="新建" ><i class="fa fa-file-o"></i> 新增规格选项</button>
</div>
<table class="table table-bordered table-striped table-hover dataTable">
<thead>
<tr>
<th class="sorting">规格选项</th>
<th class="sorting">排序</th>
<th class="sorting">操作</th>
</thead>
<tbody>
<tr>
<td>
<input class="form-control" placeholder="规格选项">
</td>
<td>
<input class="form-control" placeholder="排序">
</td>
<td>
<button type="button" class="btn btn-default" title="删除" ><i class="fa fa-trash-o"></i> 删除</button>
</td>
</tr>
<tr>
<td>
<input class="form-control" placeholder="规格选项">
</td>
<td>
<input class="form-control" placeholder="排序">
</td>
<td>
<button type="button" class="btn btn-default" title="删除" ><i class="fa fa-trash-o"></i> 删除</button>
</td>
</tr>
<tr>
<td>
<input class="form-control" placeholder="规格选项">
</td>
<td>
<input class="form-control" placeholder="排序">
</td>
<td>
<button type="button" class="btn btn-default" title="删除" ><i class="fa fa-trash-o"></i> 删除</button>
</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button class="btn btn-success" data-dismiss="modal" aria-hidden="true">保存</button>
<button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
</div>
</div>
</div>
</div>
</body>
</html>