B2B2C-2 品牌管理-3-增加品牌的实现

1.保存的结果返回:

1>map 包含code和message

2>实体类 使用Result

@RequestMapping("/add")
public Result add(@RequestBody TbBrand brand){
System.out.println("添加品牌");
try {
brandService.add(brand);
return new Result(true,"添加成功");
}catch(Exception e){
return new Result(false,"添加失败");
}
}

 

2.前端新增功能:

每个模块增加ng-model="brand.name"

保存按钮增加 ng-click="add()"

新建按钮增加ng-click="brand={}"

如果重复校验的话可以在后台数据库中的name加唯一约束或者在后台代码添加;

$scope.add=function(){
$http.post("../brand/add.do",$scope.brand).success(
function(response){
if(response.success){
$scope.reloadList();
}else{
alert(response.message);
}
}
);
}
<td><input  class="form-control" placeholder="品牌名称" ng-model="brand.name" >  </td>

<button class="btn btn-success" data-dismiss="modal" aria-hidden="true" ng-click="add()">保存</button>
<button type="button" class="btn btn-default" title="新建" data-toggle="modal" data-target="#editModal" ng-click="brand={}"><i class="fa fa-file-o"></i> 新建</button>
ng-click="brand={}"可以保证在点击新建按钮的时候清空数据

 

posted on 2018-09-27 16:28  companion  阅读(225)  评论(0编辑  收藏  举报