2017/3/18
1.JSONObject() 转化得到的是对象,JSONArray转化得到的数组。
2.session是全局变量,在一个Controller set,可以在另外一个包内的Controller中get到。
3. 解析在页面中输入的数据,在后台拿到。
// 解析请求数据 BasicInfo basicInfo = JsonUtil.jsonToObject(BasicInfo.class, IOUtils.toString(request.getInputStream(), Const.UTF_8));
4.textarea 在后台不能保存。
<div class="col-md-12 form-group"> <textarea id="basicInfo_description" class="wysihtml5 form-control" rows="10" ng-model="basicInfo.description"></textarea> </div>
$scope.basicInfo.description = $('#basicInfo_description').val(); $scope.apiUrl = ctx + "/saveBasicInfo"; var postData = $scope.basicInfo;
5.左右移动函数
app.controller("addRouteController", addRouteController); function addRouteController($http, $scope, $location, $filter) { initApp($http, $scope, $location, $filter); // 获取左边数据 getSpaceLeft($http, $scope, $location, $filter); // 获取右边数据 getRoute($http, $scope, $location, $filter); // 新增、删除 $scope.select = function(ifAdd) { if (ifAdd) { angular.forEach($scope.spaces, function(value, key) { if (value.checked) { value.checked = false; $scope.itemsRight.push(value); } }); for (var i = 0; i < $scope.itemsRight.length; i++) { $scope.spaces.removeByValue($scope.itemsRight[i]); } } else { itemsKey = new Array(); angular.forEach($scope.itemsRight, function(value, key) { if (!value.checked) { itemsKey.push(value); } else { value.checked = false; $scope.spaces.push(value); } }); $scope.itemsRight = itemsKey; } } // 全选、清空 $scope.selectAll = function(ifAdd) { if (ifAdd) { angular.forEach($scope.spaces, function(value, key) { value.checked = false; $scope.itemsRight.push(value); }); for (var i = 0; i < $scope.itemsRight.length; i++) { $scope.spaces.removeByValue($scope.itemsRight[i]); } } else { angular.forEach($scope.itemsRight, function(value, key) { value.checked = false; $scope.spaces.push(value); }); $scope.itemsRight = new Array(); } } // 移动 $scope.moveUp = function(ifUp) { if (ifUp) { angular.forEach($scope.spaces, function(value, key) { value.checked = false; $scope.itemsRight.push(value); }); for (var i = 0; i < $scope.itemsRight.length; i++) { $scope.spaces.removeByValue($scope.itemsRight[i]); } } else { angular.forEach($scope.itemsRight, function(value, key) { value.checked = false; $scope.spaces.push(value); }); $scope.itemsRight = new Array(); } } // 保存 $scope.save = function() { if ($('#myForm').valid()) { var spaceIds = ''; angular.forEach($scope.itemsRight, function(value, key) { if (spaceIds == '') { spaceIds = value.id; } else { spaceIds += ',' + value.id; } }); $scope.spaceIds = spaceIds; // 请求地址 $scope.apiUrl = ctx + "/saveRoute"; var config = { params: {} } // 请求数据 var postData = { route: $scope.route, spaceIds: $scope.spaceIds }; // 发送请求 $http.post($scope.apiUrl, postData, config).success(function(data, status, headers, config) { if (data.message == "OK") { var url = ctx + "/mgtRoute" window.location.href = url; } else { showDialog($scope, 'exception' + data.message); } }).error(function(data, status, headers, config) { // 处理错误 console.log("get route error"); }); } } } // 获取已选空间 function getRoute($http, $scope, $location, $filter) { var postData = {}; var config = {}; $scope.apiUrl = ctx + "/getRoute"; $http.post($scope.apiUrl, postData, config).success(function(data, status, headers, config) { // 成功之后做一些事情 $scope.route = data.route; // 右侧已选数据 $scope.itemsRight = []; angular.forEach($scope.route.routeSpaceRelations, function(value, key) { $scope.itemsRight.push(value.space); }); // 监听右侧选中数据,数据长度用于判断保存按钮是否可用 $scope.chooseItemsRight = []; $scope.$watch('itemsRight', function(newValue, oldValue) { if (newValue == oldValue) { return; } $scope.chooseItemsRight = []; angular.forEach($filter('filter')(newValue, { checked: true }), function(newValue) { $scope.chooseItemsRight.push(newValue); }); // console.log($scope.chooseItemsRight); }, true); }).error(function(data, status, headers, config) { // 处理错误 // console.log("error"); }); }
6.
只为成功找方法,不为失败找借口!