angular js 页面修改数据存入数据库

一、编写service,修改数据要根据ID回显数据

  //根据ID查询
public Brand findById(Long id);
//修改
public int update(Brand brand);
二、编写serviceImpl
@Override
public Brand findById(Long id) {
return brandDao.selectByPrimaryKey(id);
}

@Override
public int update(Brand brand) {
return brandDao.updateByPrimaryKeySelective(brand);
}
三、编写controller,修改返回Result类型
//根据ID查询回显数据
// @RequestMapping("/findById")
@RequestMapping("/{id}")
// public Brand findById(Long id){
public Brand findById(@PathVariable(value = "id")Long id){
return brandService.findById(id);
}
//修改
@RequestMapping("/update")
public Result update(@RequestBody Brand brand){
int id = brandService.update(brand);
if (id>0){
return new Result(true,"修改成功");
}else {
return new Result(false,"修改失败");
}
}

四、编写页面html
//添加保存
$scope.save=function () {
var url="../brand/save.do";
//判断是添加还是修改,添加$scope.entity.id==null,否则执行修改
if ($scope.entity.id!=null){
url="../brand/update.do"
}
//发送请求$http.post(url,$scope.entity),第一个参数是请求地址,第二个参数是提交的数据
$http.post(url,$scope.entity).success(function (response) {
if(response.success){
//重新加载
return $scope.reloadList();
}else {
alert(response.message);
}
});
}
//根据ID回显数据
$scope.findById=function (id) {
// $http.get('../brand/findById.do?id='+id).success(function (response) {
$http.get('../brand/'+id+'.do').success(function (response) {
$scope.entity=response;
});
}

<td class="text-center">
<button type="button" class="btn bg-olive btn-xs" data-toggle="modal"
data-target="#editModal" ng-click="findById(entity.id)" >修改</button>
</td>
//ng-click="save()",根据请求地址判断调用save
<button class="btn btn-success" data-dismiss="modal" aria-hidden="true" ng-click="save()">保存</button>

转载于:https://www.cnblogs.com/zhangrongfei/p/11332213.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值