一、编写实体类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 页面添加数据保存数据库的更多相关文章

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

    一.编写service,修改数据要根据ID回显数据 //根据ID查询 public Brand findById(Long id); //修改 public int update(Brand bran ...

  2. ThinkPHP 添加数据到数据库失败

    ThinkPHP 添加数据到数据库失败 一般情况下会先检查一下几个方面 检查控制器或Model名是否有误 检查需要插入的数据是否为空或者缺失参数 检查数据表名及字段名称(大部分下都是字段名有误出错的) ...

  3. 增删改查列表angular.js页面实现

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  4. 搭建Spring框架,实现添加数据到数据库

    原创链接:http://www.cnblogs.com/yanqin/p/5284400.html (允许转载,但请注明原创链接) 1.在myeclipse中建立一个web项目 项目名 :spring ...

  5. angular js 指令的数据传递 及作用域数据绑定

    <div my-directive my-url="http://google.com" my-link-text="Click me to go to Googl ...

  6. angular js 自定义添加依赖

    代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  7. 一个hql 关键字member(非mysql)引起的 vo 数据 保存数据库错误

    2015-03-19 14:16:29,285 ERROR [Thread-3] (DAOHelper.java:312) - updateByEntityPK:com.agileeagle.dao. ...

  8. Sharepoint2013 列表的NewForm 页面添加一个 保存新建 按钮

    昨天一同事问我如何在sharepoint2013的NewForm.aspx页面上添加一个 save and new的button.实现save 和new的功能,save的功能和默认的save按钮效果一 ...

  9. 关于从JSP页面插入数据到数据库中乱码问题的解决

    问题描述:最近我在写一个j2ee的留言板系统模块,遇到了一个非常让我头大的问题,当我从JSP页面输入数据后,通过hibernate中的业务逻辑类HQL语句把这个数据插入到本地的mysql数据库中,可是 ...

随机推荐

  1. Springboot:员工管理之添加员工(十(7))

    构建员工添加请求 com\springboot\controller\EmployeeController.java /*调转到员工添加页 携带部门信息 restful风格*/ @GetMapping ...

  2. 掌握游戏开发中类Message、Handle

    1.   实验目的 1. 自主地设计图形界面 2. 掌握消息类Message的应用 3. 掌握消息处理类Handle的应用 4. 掌握子线程中中更新UI界面的方法 2.  实验内容 1. 在主界面设置 ...

  3. java集合List

    需求:List集合存储字符串并遍历.List集合的特点: 有序(存储和取出的元素一致),可重复的.package javatest; import java.util.ArrayList;import ...

  4. JasperReports入门教程(四):多数据源

    JasperReports入门教程(四):多数据源 背景 在报表使用中,一个页面需要打印多个表格,每个表格分别使用不同的数据源是很常见的一个需求.假如我们现在有一个需求如下:需要在一个报表同时打印所有 ...

  5. Linux系统防火墙相关操作

    服务器重启后防火墙会自动开启,需要把防火墙关闭 以下为对防火墙进行的相关操作 查看防火墙状态 systemctl status firewalld service iptables status 暂时 ...

  6. SQL三表连接查询与集合的并、交、差运算查询

    use db_sqlserver2 select 姓名, 工资, 面积, 金额, (工资+金额/1000) as 实发工资 from 职工,仓库, 订购单 where 职工.职工号=订购单.职工号 a ...

  7. SpringCloudAlibaba实战教程系列

    一.简介 Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案.此项目包含开发分布式应用服务的必需组件,方便开发者通过 Spring Cloud 编程模型轻松使用这些组件来开 ...

  8. Python封装应用程序的最佳项目结构是什么?

    Python封装应用程序的最佳项目结构是什么? 转载来源于stackoverflow:https://stackoverflow.com/questions/193161/what-is-the-be ...

  9. js的call方法

    obj1.method.call(obj2,arg1,arg2,arg3...) call方法的作用就是 把obj1的方法放到obj2对象上使用 arg1,arg2....是参数,传给mehtod的哟 ...

  10. pv(PageView)的解释

    http://blog.sina.com.cn/s/blog_5007d1b10100moka.html 本文转自hblxp32151CTO博客,原文链接:http://blog.51cto.com/ ...