A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

修改品牌
5.1 需求分析
点击列表的修改按钮,弹出窗口,修改数据后点“保存”执行保存操作
图片1.png
5.1 后端代码5.1.1 服务接口层
在 pinyougou-sellergoods-interface 的 BrandService.java 新增方法定义
[AppleScript] 纯文本查看 复制代码
/**

* 修 改

*/

public  void  update(TbBrand  brand);

/**

*根据 ID 获取实体

*@param  id

*@return

*/

public  TbBrand  findOne(Long  id);
5.1.1 服务实现层
在 pinyougou-sellergoods-service 的 BrandServiceImpl.java 新增方法实现
[AppleScript] 纯文本查看 复制代码
/**

* 修 改

*/ @Override
public  void  update(TbBrand  brand){ brandMapper.updateByPrimaryKey(brand);
}



/**

*根据 ID 获取实体

*@param  id

*@return

*/ @Override
public  TbBrand  findOne(Long  id){

return  brandMapper.selectByPrimaryKey(id);

}
5.1.1 控制层
在 pinyougou-manager-web 的 BrandController.java 新增方法
[AppleScript] 纯文本查看 复制代码
/**[/size][/font][/align][font=微软雅黑][size=3]*修改

*@param  brand


*@return


*/ @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,  "修改失败");

}


}


/**

*获取实体

*@param  id


*@return


*/ @RequestMapping("/findOne")
public  TbBrand  findOne(Long  id){


return  brandService.findOne(id);


}

5.3 前端代码5.3.1 实现数据查询
增加 JS 代码
[AppleScript] 纯文本查看 复制代码
//查询实体

$scope.findOne=function(id){

$http.get('../brand/findOne.do?id='+id).success(

function(response){

$scope.entity=  response;

}

);

}
修改列表中的“修改”按钮,调用此方法执行查询实体的操作
[AppleScript] 纯文本查看 复制代码
<button	type="button"	class="btn	bg-olive	btn-xs"	data-toggle="modal" data-target="#editModal"  ng-click="findOne(entity.id)"  >修改</button>
5.3.1 file:///C:\Users\user\AppData\Local\Temp\ksohtml\wpsF665.tmp.png保存数据
修改 JS 的 save 方法
[AppleScript] 纯文本查看 复制代码
//保存

$scope.save=function(){

var  methodName='add';//方法名称

if($scope.entity.id!=null){//如果有 ID

methodName='update';//则执行修改方法
[AppleScript] 纯文本查看 复制代码
}

$http.post('../brand/'+  methodName  +'.do',$scope.entity  ).success(

function(response){ if(response.success){
//重新查询

$scope.reloadList();//重新加载

}else{

alert(response.message);

}

}

);

}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马