Springboot2模塊系列:thymeleaf+Bootstrap(五)前後端結合--數據操作

1 添加

1.0 添加頁面

在這裏插入圖片描述

圖1 添加

1.2 添加js

function click_add(){
    // var id = document.getElementById("uid").value;
    var username = document.getElementById("username").value;
    var password = document.getElementById("password").value;
    var email = document.getElementById("email").value;
    var sex = document.getElementById("sex").value;
    var position = document.getElementById("position").value;
    var telephoneNum = document.getElementById("telephoneNum").value;
    // alert(JSON.stringify({"username":username, "password":password, "email":email, "sex":sex, "position":position, "telephoneNum":telephoneNum}));
    $.ajax({
        type:'post', 
        url:'http://localhost:8091/api/page/ui/user/add/eject',
        contentType:"application/json;charset=utf-8",
        data:JSON.stringify({"username":username, "password":password, "email":email,
        "sex":sex, "position":position, "telephoneNum":telephoneNum}),
        dataType:"json",
        success: function(){
          console.log("success");
        }
      }
    );
  };

2 刪除

  • thymeleaf
<a href="datasshow/index.html" th:href="@{/api/page/ui/user/delete(id=${i.id})}"><button type="button" class="btn btn-danger">刪除</button></a>

3 修改

3.1 修改頁面

在這裏插入圖片描述

圖2 修改

3.2 修改js

function table_click_test(){
    var rows = document.getElementById("editTable").rows.length;
    console.log("rows:"+rows);
    // var uid = "";
    // var username = "";
    // var password = "";
    // var email = "";
    // var sex = "";
    // var position = "";
    // var telephoneNum = "";
    $("#editTable tr").click(function(){
      var td=$(this).find("td");
      uid = td.eq(1).html();
      console.log("uid:"+uid);
      username = td.eq(2).html();
      sex = td.eq(3).html();
      position = td.eq(4).html();
      telephoneNum = td.eq(5).html();

      console.log("uid new:"+uid);
      $('#modalTest').on('show.bs.modal', function(event){
        var modal=$(this);
        // p標籤數據
        // modal.find('.modal-body #id').text("trans data");
        // input 數據
        modal.find('.modal-body input#uid').val(uid);
        modal.find('.modal-body input#username-edit').val(username);
        modal.find('.modal-body input#password-edit').val("");
        modal.find('.modal-body input#email-edit').val("");
        modal.find('.modal-body input#sex-edit').val(sex);
        modal.find('.modal-body input#position-edit').val(position);
        modal.find('.modal-body input#telephoneNum-edit').val(telephoneNum);
        
      });
      $('#modalTest').modal('show');
    });
  };

4 查詢

4.1 查詢頁面

在這裏插入圖片描述

圖3 查詢

4.2 查詢js

function click_query(){
      var username = document.getElementById("username-query").value;
      window.location.href="http://localhost:8091/api/page/ui/user/query?username="+username;
  };
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章