电商三十、品牌删除

①先写后端代码。

一、先写服务(service)层的接口(interface)层

BrandService.java 的内容为:

package com.pinyougou.sellergoods.service;import java.util.List;import com.pinyougou.pojo.TbBrand;import entity.PageAndSize;
import entity.PageResult;/*** 品牌接口* @author Administrator**/
public interface BrandService {public List findAll();/*** 品牌分页* @param pageAndSize* @return*/public PageResult findPage(PageAndSize pageAndSize);/*** 增加* @param brand*/public void add(TbBrand brand);/*** 根据ID查询实体* @param id* @return*/public TbBrand findOne(Long id);/*** 修改* @param brand*/public void update(TbBrand brand);/*** 删除* @param ids*/public void delete(List ids);
}

二、再写服务(service)层的实现(implements)层

 

BrandServiceImpl.java 的内容为:

package com.pinyougou.sellergoods.service.impl;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.pinyougou.mapper.TbBrandMapper;
import com.pinyougou.pojo.TbBrand;
import com.pinyougou.sellergoods.service.BrandService;import entity.PageAndSize;
import entity.PageResult;@Service
public class BrandServiceImpl implements BrandService {@Autowiredprivate TbBrandMapper brandMapper; @Overridepublic List findAll() {//返回全部列表return brandMapper.selectByExample(null);}@Overridepublic PageResult findPage(PageAndSize pageAndSize) {PageHelper.startPage(pageAndSize.getPageNum(), pageAndSize.getSizeNum());Page page = (Page) brandMapper.selectByExample(null);return new PageResult(page.getTotal(),page.getResult());}@Overridepublic void add(TbBrand brand) {brandMapper.insert(brand);}@Overridepublic TbBrand findOne(Long id) {return brandMapper.selectByPrimaryKey(id);}@Overridepublic void update(TbBrand brand) {brandMapper.updateByPrimaryKey(brand);}@Overridepublic void delete(List ids) {for(Long id:ids) {	brandMapper.deleteByPrimaryKey(id);}}}

 

 

三、写控制(controller)层代码即web层代码。

 

BrandController.java 的内容为:

package com.pinyougou.manager.controller;import java.util.ArrayList;
import java.util.List;import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;import com.alibaba.dubbo.config.annotation.Reference;
import com.pinyougou.pojo.TbBrand;
import com.pinyougou.sellergoods.service.BrandService;import entity.IdResult;
import entity.PageAndSize;
import entity.PageResult;
import entity.Result;@RestController
@RequestMapping("brand")
public class BrandController {@Referenceprivate BrandService brandService;@RequestMapping("/findAll")public List findAll(){return brandService.findAll();}@RequestMapping("/findPage")public PageResult findPage(@RequestBody PageAndSize pageAndSize) {return brandService.findPage(pageAndSize);}@RequestMapping("/add")public Result add(@RequestBody TbBrand brand) {try {brandService.add(brand);return new Result(true,"增加成功");} catch (Exception e) {e.printStackTrace();return new Result(false,"增加失败");}}@RequestMapping("findOne")public TbBrand findOne(@RequestBody IdResult idResult) {return brandService.findOne(idResult.getId());}@RequestMapping("/update")public Result update(@RequestBody TbBrand brand) {try {brandService.update(brand);return new Result(true,"修改成功");} catch (Exception e) {e.printStackTrace();return new Result(false,"修改失败");}}@RequestMapping("/delete")public Result delete(@RequestBody List idResults) {	List  ids = new ArrayList();int i=0;if(idResults.size()>0) {for(IdResult idResult:idResults) {ids.add(idResult.getId());i++;}}		try {brandService.delete(ids);return new Result(true,"删除成功");} catch (Exception e) {e.printStackTrace();return new Result(false,"删除失败");}}}

 

②再写前端代码。

一、先写更新勾选CheckBox复选框的ID的代码

			                                                {{entity.id}}{{entity.name}}									     {{entity.firstChar}}		                                                                                                                       

	$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]}) ;}$http.post("../brand/delete.do",$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);}}		);				}

三、再写页面渲染完成后,复选框的显示,true为被勾选,false为不勾选。

 			                              {{entity.id}}{{entity.name}}									     {{entity.firstChar}}		                                                                                                                       

 on-finish-render-filters表示等待这个渲染完成以后,执行以下代码。

只为部分代码

品牌管理

品牌ID品牌名称 品牌首字母 操作
{{entity.id}}{{entity.name}} {{entity.firstChar}}

品牌编辑

品牌名称
首字母

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部