angular js page modify data stored in the database

First, write service, modify the data to echo data based on ID

  // query by ID 
public Brand findById (Long the above mentioned id);
// modify
public int update (Brand brand);
Second, write serviceImpl
@Override 
public the findById Brand (Long ID) {
return brandDao.selectByPrimaryKey (ID);
}

@Override
public int Update (Brand Brand) {
return brandDao.updateByPrimaryKeySelective (Brand);
}
three Controller write, modify return type 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,"修改失败");
}
}

Fourth, write html page
// Add save 
$ scope.save = function () {
var URL = "../ Brand / save.do";
// determines whether to add or modify, add $ scope.entity.id == null, modified or executed
if ($ scope.entity.id! = null) {
URL = "../ Brand / update.do"
}
// send request $ http.post (url, $ scope.entity) , the first parameter is the request address, the second parameter is the data submitted
$ http.post (URL, $ scope.entity) .success (function (Response) {
IF (response.success) {
// reloaded
return $ scope.reloadList ();
} the else {
Alert (response.message);
}
});
}
// The ID data echo
$ 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 ()", the address is determined according to a request calling save
<button class="btn btn-success" data-dismiss="modal" aria-hidden="true" ng-click="save()">保存</button>

Guess you like

Origin www.cnblogs.com/zhangrongfei/p/11332213.html