简单记录下前后端增删改查笔记

一、前端界面代码

主页面

<script>
var ctx = "${pageContext.request.contextPath}";
</script>
<div style="display:none">
<span id="ImportCustomer" style="background:#353737;color: #FFFFFF;display:none" class="btn btn-inverse webuploader-container"><div  class="webuploader-pick" >导入</div></span>
<div id="systemMeta_dlg" class="easyui-dialog" style="width: 500px; height: 300px;" closed="true" buttons="#systemMeta_dlg_buttons" modal="true">
<form id="fm">
   <table id="tb" style="border-collapse:separate;border-spacing:10px;  width:95%">
      <tr><td style="width: 120px">序号</td><td><input class="easyui-textbox" name="num" id="num" style="width:250px" readonly disabled /></td></tr>
      <tr><td>客户(合同对方)编号</td><td><input class="easyui-textbox" id="customId" name="customId" style="width:250px" /></td></tr>
      <tr><td>客户(合同对方)</td><td><input class="easyui-textbox" id="customName" name="customName" style="width:250px" /></td></tr>
      <tr><td>用章文件类别</td>
            <td><select class="easyui-combobox" id="documentType" style="width:250px"><option value="">--请选择--</option>
                   <option value="销售订单类">销售订单类</option><option value="合同类文件">合同类文件</option><option value="非合同类文件">非合同类文件</option></select> 
           </td>
       </tr>
      <tr><td>合同名称</td><td><input class="easyui-textbox" id="contractName" name="contractName" style="width:250px" /></td></tr>
      <tr><td>签名关键字</td><td><input class="easyui-textbox"  id="signatureKeyword" name="signatureKeyword" style="width:250px" /></td></tr>
      <tr><td>印章关键字</td><td><input class="easyui-textbox"  id="stampkeyword" name="stampkeyword" style="width:250px" /></td></tr>
    </table>
</form>
</div>

<div id="systemMeta_dlg_buttons">
  <a id="system_meta_dlg_btnsave" href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="createOrUpdate()" style="width: 90px">保存</a> 
  <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#systemMeta_dlg').dialog('close')" style="width: 90px">取消</a>
</div>
</div>

<table id="dg" pageNumber="1" pageSize="50" checkOnSelect="false" 
               pagination="true" rownumbers="true" toolbar="#toolbar" remoteSort="false" class="easyui-datagrid"  pageList= "[20,50,100,200,500,1000]"
               selectOnCheck="false" showFooter="true" fit="true">
        <thead>
            <tr>
                  <th field="cb" checkbox="true" align="center">序号</th>
                  <th data-options="field:'id',width:150,hidden: true" sortable="true" >id</th>
                  <th data-options="field:'customId',width:150" sortable="true">客户(合同对方)编号</th>
                  <th data-options="field:'customName',width:200" sortable="true">客户(合同对方)</th>
                  <th data-options="field:'documentType',width:100" sortable="true">用章文件类别</th>
                  <th data-options="field:'contractName',width:100" sortable="true">合同名称</th>
                  <th data-options="field:'signatureKeyword',width:100" sortable="true">签名关键字</th>
                  <th data-options="field:'stampkeyword',width:100" sortable="true">印章关键字</th>
            </tr>
      </thead>
</table>

<div id="toolbar">
	<div>
		<table>
			<tr>
                                 客户编号: <input  id="searchCustomerId" style="width:150px"/>
                                 客户(合同对方): <input  id="searchCustomName" style="width:150px"/>
                                 用章文件类别:  <sot:combobox name="searchDocumentType" id="searchDocumentType" cssstyle="width:150px" staticvalue="|--请选择-- "  dynamicData="com.gzsolartech.bpmportal.controller.SystemMetaReflectionController" param="AD00016_DocumentType"  echo="true"/>
                                 合同名称: <input  id="searchContractName" style="width:150px"/>
                        </tr>
                        <tr>
                                <a href="javascript:selectSystemMeta()" iconCls="icon-search" class="easyui-linkbutton " plain="true" >查询</a>
                                <a href="javascript:void(0)" iconCls="icon-add" class="easyui-linkbutton " plain="true" onclick="createSystemMeta()">添加</a>
                                <a href="javascript:void(0)" iconCls="icon-remove" class="easyui-linkbutton " plain="true" onclick="deleteSystemMeta()">删除</a>  
			</tr>
		</table>
	</div>
</div>

页面JS代码

<script>
var ctx = "${pageContext.request.contextPath}";
$(function() {
	queryData();
})

//按条件搜索
function queryData() {
	var returnData = {};
    var searchCustomerId =$.trim($("#searchCustomerId").val());
    var searchCustomName =$.trim( $("#searchCustomName").val());
    if($("#searchDocumentType option:selected").text() == "--请选择--"){
       var searchDocumentType = '';
    }else{
       var searchDocumentType = $("#searchDocumentType option:selected").text();
    }
    
    var searchContractName = $.trim($("#searchContractName").val());
	$('#dg').datagrid({
		url : ctx + '/AD00016/selectByConditions.action',
      	queryParams : {
            customId : searchCustomerId,
            customName : searchCustomName,
            documentType : searchDocumentType,
            contractName : searchContractName,
		},
		onDblClickRow : function(index, row) {
			updateSystemMeta(index, row);
		}
	});
}
  
//增加数据
function createOrUpdate() {
    /*方式一
                     var meta = [];
                     var fm = $('#fm').serializeArray();
                     meta.push({
                       num : $("#num").val(),
                       metaName1 : basicCode,
                       metaName2 : metaName2,
                       metaName3 : $("#metaName3").val(),
                       metaName4 : $("#metaName4").val(),
                       metaName5 : $("#metaName5").val(),
                       metaName6 : $("#metaName6").combobox('getValue'),
                       metaName7 : $("#metaName7").val(),
                       metaName8 : $("#metaName8").val(),
                       metaName9 : $("#metaName9").combobox('getValue'),
                       metaName13 : $("#metaName13").val(),
                       s_province: $("#s_province option:selected").val(),
                       s_city: $("#s_city option:selected").val(),
                       s_region: $("#s_county option:selected").val(),
                       country:''
                   });
                 saveCustomer(meta);
    */
    var meta = {};
    var flag= false;
    var fm = $('#fm').serializeArray();
    $.each(fm, function() {
      var value =  this.value;
      meta[this.name] = value;
    });
    meta.num = $("#num").val();
    meta.documentType = $("#documentType").combobox('getValue');
    
    var customId = $("#customId").val();
    var yzlbxsht = $("#documentType").combobox('getValue');
    var contractXSName = $("#contractName").val();
    var sql = "select * from AAC_AD00016_TemplateConfig where CUSTOMID = '"+customId+"'"+" and  documentType = '" +yzlbxsht+"' and  CONTRACTNAME= '"+contractXSName+"'";//根据客户(合同对方)编号、用章文件类别 、合同名称确定关键字
    var returnVal = getGlgc(sql);
    if (returnVal && returnVal.length > 0) {
          $.messager.confirm(
							'温馨提示','已有合同编号:'+customId+'用章文件类别:'+yzlbxsht+'合同名称:'+contractXSName+'的数据,是否覆盖?',
							function(r) {
								if (r) {
                                        //保存数据
                                       flag =true;
                                       saveCustomer([meta],flag);
								}
			});
    }else{
        //保存数据
        flag =false;
        saveCustomer([meta],flag);
    }
    
    $('#systemMeta_dlg').dialog('close');
    $('#dg').datagrid('reload');
}
  
function saveCustomer(rows,flag){
	$.ajax({
		url : ctx+"/AD00016/createOrUpdate.action",
		async : false,
		type : "post",
		data : {
			data : JSON.stringify(rows),
            flag :flag
		},
		dataType : "json",
		success : function(data) {
			returnData = data;
		}
	});
}

function updateSystemMeta(index, row) {
	$('#fm').form('clear');
	$("#num").textbox('setValue', row.id);
	$("#customId").textbox('setValue', row.customId);
    $('#customId').textbox('textbox').attr('readonly',true); 
	$("#customName").textbox('setValue', row.customName);
    $('#customName').textbox('textbox').attr('readonly',true); 
	$("#documentType").combobox('setValue',  row.documentType);
    $("#documentType").combobox('readonly',true); //只读
	$("#contractName").textbox('setValue', row.contractName);
    $('#contractName').textbox('textbox').attr('readonly',true); 
	$("#signatureKeyword").textbox('setValue', row.signatureKeyword);
	$("#stampkeyword").textbox('setValue', row.stampkeyword);
    $('#systemMeta_dlg').dialog('open').dialog('setTitle', '添加');
}

function deleteSystemMeta() {
	var rows = $('#dg').datagrid('getChecked');
    if (rows.length > 0) {
    		$.messager.confirm(
							'温馨提示','你真的要删除么,删除了会被挨叼的哦?',
							function(r) {
								if (r) {
                                      var ids = [];
                                      for ( var i in rows) {
                                        ids.push(rows[i].id);
                                      }
                                      $.ajax({
                                        url : ctx+'/AD00016/deleteDataByCondition.action',
                                        async : true,
                                        type : "post",
                                        data : {
                                          ids : ids
                                        },
                                        dataType : "json",
                                        success : function(result) {
                                          return result;
                                        }
                                      });
                                      $('#dg').datagrid('reload');
                                      queryData();
								}
			});
    }
	
}
  
function selectSystemMeta() {
    var searchCustomerId =  $.trim($("#searchCustomerId").val());
    var searchCustomName =  $.trim($("#searchCustomName").val());
    if($("#searchDocumentType option:selected").text() == "--请选择--"){
      var searchDocumentType = '';
    }else{
      var searchDocumentType = $("#searchDocumentType option:selected").text();
    }
    var searchContractName =  $.trim($("#searchContractName").val());
	$('#dg').datagrid("reload",{
      customId:searchCustomerId,
      customName:searchCustomName,
      documentType:searchDocumentType,
      contractName:searchContractName
    });
}

function createSystemMeta() {
	$('#fm').form('clear');
	$('#systemMeta_dlg').dialog('open').dialog('setTitle', '添加');
    $('#customId').textbox('textbox').attr('readonly',false); 
    $("#documentType").combobox('readonly',false); //取消只读
    $('#customName').textbox('textbox').attr('readonly',false); 
    $('#contractName').textbox('textbox').attr('readonly',false); 
}
  
//传SQL查找结果集
function getGlgc(sql) {
        var returnVal = '';
        $.ajax({
            url: '${pageContext.request.contextPath}/bpmportal/sysmetadatacontroller/getNetadataBySql.action',
            async: false,
            type: "post",
            data: {
                sql: sql
            },
            dataType: "json",
            success: function (result) {
                returnVal = result;
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                //returnVal = 'error';
            }
        });
        return returnVal;
    }  
</script>  

二、后端代码

AD00016Controller

@Controller
@RequestMapping("/AD00016")
public class AD00016Controller {
    @Autowired
    AD00016Service ad00016Service;
    private static final Logger LOG = LoggerFactory.getLogger(AD00016Controller.class);

    // AD00016销售合同关键字配置表删除数据
    @RequestMapping("/deleteDataByCondition")
    @ResponseBody
    public void deleteDataByCondition(@RequestParam("ids[]") List<String> ids) {
        if(ids.size() > 0){
            ad00016Service.deleteDataByCondition(ids);
        }
    }

    // 查询AD00016销售合同关键字配置表数据
    @RequestMapping("/selectByConditions")
    @ResponseBody
    public Map<String, Object> selectByConditions(Integer page, Integer rows, String customId, String customName, String documentType,String contractName) {
        Map<String, Object> results = new HashMap<String, Object>();
        try {
            results = ad00016Service.selectByConditions(page, rows, customId, customName,documentType,contractName);
        } catch (Exception e) {
            LOG.error("获取AD00016销售合同关键字配置表信息时出现错误:", e);
            results.put("state", false);
            results.put("msg", e.getMessage());
        }
        return results;
    }


    // 插入AD00016销售合同关键字配置表数据
    @RequestMapping("/createOrUpdate")
    @ResponseBody
    public Map<String, Object> createOrUpdate(String data,String flag) {
        Map<String, Object> results = new HashMap<String, Object>();
        try {
            ad00016Service.createOrUpdate(data,flag);
            results.put("state", true);
        } catch (Exception e) {
            LOG.error("新建或更新AD00016销售合同关键字配置表数据时出现错误:", e);
            results.put("state", false);
            results.put("msg", e.getMessage());
        }
        return results;
    }

}

AD00016Service

@Service
public class AD00016Service {
    private static final Logger LOG = LoggerFactory.getLogger(AD00016Service.class);
    @Autowired
    protected GenericDao gdao;
    @Autowired
    private DatDocumentService datDocumentService;
    @Autowired
    private DatApplicationService datApplicationService;

    public void deleteDataByCondition(List<String> ids) {
        String sql = "delete AACAD00016TemplateConfig t where t.id in(:ids)";
        Query query = gdao.getSession().createQuery(sql);
        query.setParameterList("ids", ids);
        query.executeUpdate();
    }

    public Map<String, String> createOrUpdate(String data,String flag) {
        Map<String, String> result = new HashMap<String, String>();
        JSONArray myJsonArray = new JSONArray(data);
        for(int i=0;i<myJsonArray.length();i++){
            JSONObject myJsonObject = myJsonArray.getJSONObject(i);
            String ID = myJsonObject.optString("num");
            String customId = myJsonObject.optString("customId");
            String customName = myJsonObject.optString("customName");
            String documentType = myJsonObject.optString("documentType");
            String contractName = myJsonObject.optString("contractName");
            String signatureKeyword = myJsonObject.optString("signatureKeyword");
            String stampkeyword = myJsonObject.optString("stampkeyword");
            String sql = "";
            if (ID != null && !(ID.equals("")) && !(ID.isEmpty())) {
                sql = "UPDATE AAC_AD00016_TemplateConfig SET customId='"+customId+"',customName='"+customName+"',"
                        + "documentType='"+documentType+"',contractName='"+contractName+"',signatureKeyword='"+signatureKeyword+"',"
                        + "stampkeyword='"+stampkeyword+"'"+" WHERE ID ='"+ID+"'";
            } else if(flag.equals("false")){
                sql = "INSERT INTO AAC_AD00016_TemplateConfig (ID, customId,customName,documentType,contractName,signatureKeyword,stampkeyword,templateId)"
                        + " VALUES('"+UUID.randomUUID().toString().replace("-", "")+"','"+customId+"','"+customName+"','"+documentType+"','"+contractName+"','"+signatureKeyword+"',"
                        + "'"+stampkeyword+"',"+"0"+")";
            }else{
                sql = "UPDATE AAC_AD00016_TemplateConfig SET customId='"+customId+"',customName='"+customName+"',"
                        + "documentType='"+documentType+"',contractName='"+contractName+"',signatureKeyword='"+signatureKeyword+"',"
                        + "stampkeyword='"+stampkeyword+"'"+" WHERE customId ='"+customId+"',and documentType = '"+documentType+"',and contractName = '"+contractName+"'";
            }
            gdao.executeJDBCSql(sql);
        }
        return result;
    }


    public Map<String, Object> selectByConditions(Integer page, Integer rows, String customId, String customName, String documentType,String contractName) {
        String hql = "from AACAD00016TemplateConfig where 1=1 ";
        Long totalNum = (long) 0;
        if (StringUtils.isNotEmpty(customName)) {
            hql += "  and customName  like '%" + customName+"%'";
        } else if (StringUtils.isNotEmpty(documentType)) {
            hql += "  and documentType  like '%" + documentType+"%'";
        } else if (StringUtils.isNotEmpty(contractName)) {
            hql += "  and contractName  like '%" + contractName+"%'";
        } else if (StringUtils.isNotEmpty(customId)) {
            hql += "  and customId  like '%" + customId+"%'";
        } else if (StringUtils.isNotEmpty(customName)) {
            hql += "  and customName  like '%" + customName+"%'";
        }
        List list = gdao.findByPage(hql , page, rows);
        totalNum = gdao.count(hql);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("total", totalNum);
        map.put("rows", list);
        return map;
    }
}

实体类表AACAD00016TemplateConfig

@Entity
@Table(name = "AAC_AD00016_TemplateConfig")
public class AACAD00016TemplateConfig {
    private String id;//id
    private String templateId;//模板id
    private String customId;//客户(合同对方)编号
    private String customName;//客户(合同对方)
    private String documentType;//用章文件类别
    private String contractName;//合同名称
    private String signatureKeyword;//签名关键字
    private String stampkeyword;//印章关键字

    public AACAD00016TemplateConfig() {
    }

    public AACAD00016TemplateConfig(String id, String customId,  String templateId, String customName, String documentType, String contractName, String signatureKeyword, String stampkeyword) {
        this.id = id;
        this.customId = customId;
        this.templateId = templateId;
        this.customName = customName;
        this.documentType = documentType;
        this.contractName = contractName;
        this.signatureKeyword = signatureKeyword;
        this.stampkeyword = stampkeyword;
    }

    @Id
    @Column(name = "ID")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
    @Column(name = "CUSTOMID")
    public String getCustomId() {
        return customId;
    }

    public void setCustomId(String customId) {
        this.customId = customId;
    }
    @Column(name = "CUSTOMNAME")
    public String getCustomName() {
        return customName;
    }

    public void setCustomName(String customName) {
        this.customName = customName;
    }
    @Column(name = "DOCUMENTTYPE")
    public String getDocumentType() {
        return documentType;
    }

    public void setDocumentType(String documentType) {
        this.documentType = documentType;
    }
    @Column(name = "CONTRACTNAME")
    public String getContractName() {
        return contractName;
    }
    @Column(name = "TEMPLATEID")
    public String getTemplateId() {
        return templateId;
    }

    public void setTemplateId(String templateId) {
        this.templateId = templateId;
    }

    public void setContractName(String contractName) {
        this.contractName = contractName;
    }
    @Column(name = "SIGNATUREKEYWORD")
    public String getSignatureKeyword() {
        return signatureKeyword;
    }

    public void setSignatureKeyword(String signatureKeyword) {
        this.signatureKeyword = signatureKeyword;
    }
    @Column(name = "STAMPKEYWORD")
    public String getStampkeyword() {
        return stampkeyword;
    }

    public void setStampkeyword(String stampkeyword) {
        this.stampkeyword = stampkeyword;
    }
}

三、界面效果

3.1查询

在这里插入图片描述

3.2 添加

请添加图片描述

3.3 修改

请添加图片描述

3.4 删除

请添加图片描述
参考文章
https://blog.csdn.net/lkforce/article/details/86698442
https://blog.csdn.net/weixin_34314962/article/details/85918538
https://blog.csdn.net/qq_23113521/article/details/78801689

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值