SoFunction
Updated on 2025-04-08

Tutorial on adding, deleting and modifying databases by built-in service $http

This article mainly introduces the relevant content of the built-in service $http to add, delete and modify the database. It is shared for your reference and learning. Let’s take a look at the detailed introduction below:

1. Use $http to query MySQL data

('app',[])
.controller('MyCtrl',function ($scope,$http) {
 $('http://127.0.0.1:80/user/getUsers')
 .success(function (resp) {
  (resp);
 })
 .error()
 //jQuery
 /*$.get('url',function (data) {
  
 });*/
})

Corresponding background Java code:

public void getUsers(){
  List<User> users = ("select * from t_user");
renderJson(Users);
}

2. $http implements the addition, deletion and modification of data

(1)$http sends request with parameters

(2) Add, delete and modify MySQL data

&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
 &lt;meta charset="UTF-8"&gt;
 &lt;title&gt;AngularJS $http&lt;/title&gt;

 &lt;link rel="stylesheet" href="css/" rel="external nofollow" &gt;
 &lt;style type="text/css"&gt;
  html,body{font-size:14px;}
 &lt;/style&gt;
&lt;/head&gt;
&lt;body style="padding:10px;" ng-app="app"&gt;
 &lt;div ng-controller="MyCtrl"&gt;
  &lt;input type="text" ng-model="id"&gt;
  &lt;input type="text" ng-model="name"&gt;
  &lt;button class="button" onclick="addUser()"&gt;Add to&lt;/button&gt;
  &lt;button class="button" onclick="delUser()"&gt;delete&lt;/button&gt;
 &lt;/div&gt;
&lt;/body&gt;
&lt;script src="js/"&gt;&lt;/script&gt;
&lt;script src=""&gt;&lt;/script&gt;
&lt;/html&gt;
('app', [])
 .controller('MyCtrl', function ($scope, $http) {
  $=" ";
  $=" ";
  $ = function () {
   $('http://127.0.0.1:80/user/addUser',{id:$, name:$})
    .success(function (resp) {
     if(){
      alert("Added successfully");
     }
    })
  }
  $ = function () {
   $('http://127.0.0.1:80/user/delUser',{id:$})
   .success(function () {
    if(){
     alert('Delete successfully');
    }
   })
  }
 })

Background Java code:

public void addUser(){
  String id = getPara("id");
  String name = getPara("name");
  User user = new User();
  boolean isok = false;
  if(id != null && ("")){
   isok = ("id",id).set("name",name).update();
  }else{
   isok = ("name",name).save();
  }
  renderJson("seccess",isok);
}

public void delUser(){
  String id = getPara("id");
  boolean isok = (id);
  renderJson("seccess",isok);
}

Summarize

The above is the entire content of this article. I hope that the content of this article will be of some help to everyone’s learning or use. If you have any questions, you can leave a message to communicate. Thank you for your support.