angular js 页面添加数据保存数据库
一、编写实体类Controller层返回数据使用
package entity; import java.io.Serializable; public class Result implements Serializable{ private static final long serialVersionUID = -8946453797496982517L; private boolean success;
private String message;
public Result(boolean success, String message) {
super();
this.success = success;
this.message = message;
} public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
} }
二、编写service
//添加
public void save(Brand brand);
三、编写serviceImpl
@Override
public void save(Brand brand) {
brandDao.insertSelective(brand);
}
四、编写controller
//添加
@RequestMapping("/save")
public Result save(@RequestBody Brand brand){
try {
brandService.save(brand);
return new Result(true,"添加成功");
}catch (Exception e){
e.printStackTrace();
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);
}
});
}
//ng-model="entity.name",封装到对象,才可以进行保存:name=>>entity=>>$scope=>>调save()方法存入数据库
<tr>
<td>品牌名称</td>
<td><input class="form-control" placeholder="品牌名称" ng-model="entity.name" > </td>
</tr>
<tr>
<td>首字母</td>
<td><input class="form-control" placeholder="首字母" ng-model="entity.firstChar" > </td>
</tr>
//ng-click="entity={}"点击新建清空缓存,新建页面数据栏为空,不给空值有缓存数据
<button ng-click="entity={}" type="button" class="btn btn-default" title="新建"
data-toggle="modal" data-target="#editModal" ><i class="fa fa-file-o"></i> 新建</button>
<button class="btn btn-success" data-dismiss="modal" aria-hidden="true" ng-click="save()">保存</button>
angular js 页面添加数据保存数据库的更多相关文章
- angular js 页面修改数据存入数据库
一.编写service,修改数据要根据ID回显数据 //根据ID查询 public Brand findById(Long id); //修改 public int update(Brand bran ...
- ThinkPHP 添加数据到数据库失败
ThinkPHP 添加数据到数据库失败 一般情况下会先检查一下几个方面 检查控制器或Model名是否有误 检查需要插入的数据是否为空或者缺失参数 检查数据表名及字段名称(大部分下都是字段名有误出错的) ...
- 增删改查列表angular.js页面实现
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
- 搭建Spring框架,实现添加数据到数据库
原创链接:http://www.cnblogs.com/yanqin/p/5284400.html (允许转载,但请注明原创链接) 1.在myeclipse中建立一个web项目 项目名 :spring ...
- angular js 指令的数据传递 及作用域数据绑定
<div my-directive my-url="http://google.com" my-link-text="Click me to go to Googl ...
- angular js 自定义添加依赖
代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- 一个hql 关键字member(非mysql)引起的 vo 数据 保存数据库错误
2015-03-19 14:16:29,285 ERROR [Thread-3] (DAOHelper.java:312) - updateByEntityPK:com.agileeagle.dao. ...
- Sharepoint2013 列表的NewForm 页面添加一个 保存新建 按钮
昨天一同事问我如何在sharepoint2013的NewForm.aspx页面上添加一个 save and new的button.实现save 和new的功能,save的功能和默认的save按钮效果一 ...
- 关于从JSP页面插入数据到数据库中乱码问题的解决
问题描述:最近我在写一个j2ee的留言板系统模块,遇到了一个非常让我头大的问题,当我从JSP页面输入数据后,通过hibernate中的业务逻辑类HQL语句把这个数据插入到本地的mysql数据库中,可是 ...
随机推荐
- Springboot:修改默认端口以及Logo(三)
端口修改 在application.yml文件中增加端口的配置: server: port: 8081 Logo修改 Logo生成网址: https://www.bootschool.net/asci ...
- linq深入
一.匿名类:[ C# 3.0/.NET 3.x 新增特性 ] 1.1 不好意思,我匿了 在开发中,我们有时会像下面的代码一样声明一个匿名类:可以看出,在匿名类的语法中并没有为其命名,而是直接的一个ne ...
- s3cmd s3命令行工具
Amazon S3 Tools: Command Line S3 Client Software and S3 Backup 官方网站
- python-Django收集主机信息json格式
Control: from django.conf.urls import patterns, include, url from django.contrib import admin admin. ...
- 开发者福利!百问I.MX6ULL裸机文档发布
终于等到你,百问科技近600页的100ask_imx6ull裸机文档发布,已经合并到“嵌入式Linux应用开发完全手册第2版_韦东山全系列视频文档全集.pdf(1222页)”,所有人免费下载学习. 本 ...
- SpringBoot系列(十一)拦截器与拦截器链的配置与使用详解,你知道多少?
往期推荐 SpringBoot系列(一)idea新建Springboot项目 SpringBoot系列(二)入门知识 springBoot系列(三)配置文件详解 SpringBoot系列(四)web静 ...
- 开发一款图片压缩工具(三):使用 click 实现命令行
上一篇实现了图片的压缩函数.现在如果需要对图片进行压缩,可以调用实现的函数进行压缩: pngquant_compress('elephant.png', force=True, quality=20) ...
- Linux安全实验缓冲区溢出
缓冲区溢出实验: 缓冲区溢出是指程序试图向缓冲区写入超出预分配固定长度数据的情况.这一漏洞可以被恶意用户利用来改变程序的流控制,甚至执行代码的任意片段.这一漏洞的出现是由于数据缓冲器和返回地址的暂时关 ...
- [Windows] DiskPart commands
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/diskpart
- 与IBM的Lin Sun关于Istio 1.0和微服务的问答
北京时间 7 月 31 日,Istio 正式发布了 1.0 版本,并表示已经可用于生产环境.该版本的主要新特性包括跨集群 mesh 支持.细粒度流量控制以及在一个 mesh 中增量推出 mutual ...