bootstrap之增删改查

后台使用spring boot和spring cloud等。前端使用bootstrap框架进行基本操作,项目采用前后端分离。

1、查询




//对应以上HTML的js中的代码
$('#ttCompanyDemoDataTable').bootstrapTable({ silent: true, sidePagination: "server", queryParamsType: '', //默认值为 'limit' ,在默认情况下 传给服务端的参数为:offset,limit,sort -----> 设置为 '' 在这种情况下传给服务器的参数为:pageSize,pageNumber search: true, //搜索框 formatSearch: function () { return '道路名称,区域名称'; }, striped: true, //是否显示行间隔色 showRefresh: true, //刷新按钮 minimumCountColumns: 2, //最少允许的列数 clickToSelect: true, //点击选中 singleSelect: true, pagination: true, //分页 pageNumber: 1, //初始化加载第一页,默认第一页 pageSize: 20, //每页的记录行数(*) pageList: [20, 50, 100, 200], //可供选择的每页的行数(*) paginationLoop: false, //循环翻页 sortable: false, //是否启用排序 escape: true, //html字符转义 toolbar: '#toolbar', columns: [ {field: 'state', checkbox: true}, {field: 'userName', title: '用户名', sortable: false, align: 'left'}, {field: 'userPassword', title: '密码', sortable: false, align: 'left'}, {field: 'userRealname', title: '真实姓名', sortable: false, align: 'left'}, { field: 'dataEnable', title: '数据状态', sortable: false, align: 'left', formatter: function (value) { if (value) { if (value == 1) { return '有效'; } else if (value == -1) { return '无效'; } else { return '未知'; } } } } ], ajax: function (params) { //定义条件 var pageSize=params.data.pageSize; var pageNumber=params.data.pageNumber; var dataEnable=$('#dataEnableSelect').val(); var searchText=params.data.searchText; //发起请求 $.ajax({ url: EW_API_BASE_PATH + '/udp/api/service/ttCompanyDemo/list', type: 'POST', async: true, //contentType: "application/json;charset=utf-8", dataType: "json", //data: JSON.stringify(params.data), data: {dataEnable:dataEnable,searchText:searchText,pageSize:pageSize,pageNumber:pageNumber}, headers: { 'companyUserToken': getToken(), 'rmsServiceCode': 'WHJT_SERVICE_TtCompanyDemo_list' }, success: function (data) { params.success(data.result); } }); } });

2、新增

  "addTtCompanyDemoBtn" class="waves-effect waves-button" href="javascript:;">
            class="zmdi zmdi-plus">
            新增
      
//新增按钮
    $('#addTtCompanyDemoBtn').click(function () {
        //弹框
        $.confirm({
            title: '新增',
            content: 'url:/whjt-ui/module/whjt/xtgl/ttCompanyDemo/add.html',
            closeIcon: true,
            boxWidth: '300px',
            useBootstrap: false,
            buttons: {
                save: {
                    text: '保存',
                    btnClass: 'waves-effect waves-button',
                    action: function () {
                        //拼装对象
                        var dataForm=$('#dataForm').serialize();
                        var userName=$('#userName').val();
                        var userPassword=$('#userPassword').val();
                        var userRealname=$('#userRealname').val();
                        //定义返回值
                        var rv = false;
                        //数据校验
                        if(userName==''||userName==null) {
                            $('#userName').focus();
                            showToastr({
                                "positionClass": "toast-top-center",
                            }, "warning", "提醒", "请输入用户名");
                            return rv;
                        }
                        if(userPassword==''||userPassword==null) {
                            $('#userPassword').focus();
                            showToastr({
                                "positionClass": "toast-top-center",
                            }, "warning", "提醒", "请输入密码");
                            return rv;
                        }
                         if(userRealname==''||userRealname==null){
                             $('#userRealname').focus();
                             showToastr({
                                 "positionClass": "toast-top-center",
                             },"warning","提醒","请输入真实姓名");
                             return rv;

                        } else{
                        //发起请求
                        $.ajax({
                            url: EW_API_BASE_PATH + '/udp/api/service/ttCompanyDemo/save',
                            type: 'POST',
                            async: false,
                            //contentType: "application/json;charset=utf-8",
                           // dataType: "json",  //Ajax无返回值时,设置dataType会报错
                            headers: {
                                'companyUserToken': getToken(),
                                'rmsServiceCode': 'WHJT_SERVICE_TtCompanyDemo_save'
                            },
                            data: dataForm,
                            success: function () {
                                rv = true;
                                $('#ttCompanyDemoDataTable').bootstrapTable('refresh');
                            }
                        });
                        //返回
                        return rv;
                       }

                    }
                }
            }
        });
    });
add.html代码部分

















 

 

转载于:https://www.cnblogs.com/jincheng81/p/9152566.html

你可能感兴趣的:(bootstrap之增删改查)