前台代码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SYSISQDF维护</title>
<link rel="stylesheet"
href="${pageContext.request.contextPath}/unauthed/JavaScript/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet"
href="${pageContext.request.contextPath}/unauthed/JavaScript/bootstrap/table/bootstrap-table.css">
<link rel="stylesheet"
href="${pageContext.request.contextPath}/unauthed/JavaScript/bootstrap/datetimepicker/bootstrap-datetimepicker.css">
<link rel="stylesheet"
href="${pageContext.request.contextPath}/unauthed/JavaScript/bootstrap/validator/bootstrapValidator.css">
<script type="text/javascript"
src="${pageContext.request.contextPath}/unauthed/JavaScript/jquery/jquery-1.11.3.min.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath}/unauthed/JavaScript/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath}/unauthed/JavaScript/bootstrap/table/bootstrap-table.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath}/unauthed/JavaScript/bootstrap/table/locale/bootstrap-table-zh-CN.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath}/unauthed/JavaScript/bootstrap/table/tableExport.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath}/unauthed/JavaScript/bootstrap/table/extensions/export/bootstrap-table-export.min.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath}/unauthed/JavaScript/bootstrap/datetimepicker/bootstrap-datetimepicker.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath}/unauthed/JavaScript/bootstrap/datetimepicker/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript"
src="${pageContext.request.contextPath}/unauthed/JavaScript/bootstrap/validator/bootstrapValidator.min.js"></script>
<style type="text/css">
</style>
<script type="text/javascript">
$(function(){
PageLoader.initTable1();
PageLoader.initTable();
PageLoader.initFormValidator();
PageLoader.initFormValidator1();
});
PageLoader = {
initTable : function() {
$("#mytable1").bootstrapTable({
columns : [ {
field : 'radio',
radio : true
}, {
field : 'index',
title : '序号',
formatter : function(value, row, index) {
return index + 1;
}
}, {
field : 'CUST_BIC',
title : 'BIC'
}, {
field : 'CUST_ACCOUNT',
title : '分账号'
} ],
url : '${pageContext.request.contextPath}/sysis/sysisqf.action',
pagination : true,
paginationHAlign : 'left',
pageSize : 10,
height : 520,
clickToSelect : true,
onClickRow : function(row, ele) {
$("#thisForm1").data('bootstrapValidator');
$('#thisForm1').data('bootstrapValidator', null);
PageLoader.initFormValidator1();
$("#CUST_BIC1").attr("readonly", "readonly");
$("#CUST_ACCOUNT1").attr("readonly", "readonly");
TransferLHMToField1(row);
}
});
},
initFormValidator : function() {
$('#thisForm').bootstrapValidator({
message : 'this value is not valid',
feedbackIcons : {
valid : 'glyphicon glyphicon-ok',
invalid : 'glyphicon glyphicon-remove',
validating : 'glyphicon glyphicon-refresh'
}
});
},
initFormValidator1 : function() {
$('#thisForm1').bootstrapValidator({
message : 'this value is not valid',
feedbackIcons : {
valid : 'glyphicon glyphicon-ok',
invalid : 'glyphicon glyphicon-remove',
validating : 'glyphicon glyphicon-refresh'
}
});
},
initTable1 : function() {
$("#mytable").bootstrapTable({
columns : [ {
field : 'radio',
radio : true
}, {
field : 'index',
title : '序号',
formatter : function(value, row, index) {
return index + 1;
}
}, {
field : 'CUST_BIC',
title : 'BIC',
align:'center',
sortable:'true'
}, {
field : 'CUST_ACCOUNT',
title : '分账号',
align:'center',
sortable:'true'
} ],
url : '${pageContext.request.contextPath}/sysis/sysisqd.action',
pagination : true,
paginationHAlign : 'left',
pageSize : 10,
height : 520,
clickToSelect : true,
onClickRow : function(row, ele) {
$("#thisForm").data('bootstrapValidator').destroy();
$('#thisForm').data('bootstrapValidator', null);
PageLoader.initFormValidator();
$("#CUST_BIC").attr("readonly", "readonly");
$("#CUST_ACCOUNT").attr("readonly", "readonly");
TransferLHMToField(row);
}
});
},
}
//表单元素自动赋值
function TransferLHMToField(json) {
if (json) {
for ( var index in json) {
var elm = document.getElementById(index);
if (elm) {
if ("SELECT" == elm.nodeName) {
$("#CUST_BIC").val(json.CUST_BIC);
$("#CUST_ACCOUNT").val(json.CUST_ACCOUNT);
//$(elm).val(json[index]);
} else if ("INPUT" == elm.nodeName) {
if ("radio" == elm.type) {
$("input:radio[id='CUST_BIC'][value='"+ json.CUST_ACCOUNT + "']").attr("checked", true);
$("input:radio[id='CUST_ACCOUNT'][value='"+ json.CUST_ACCOUNT + "']").attr("checked", true);
} else if ("checkbox" == elm.type) {
if (elm.value == json[index]) {
elm.checked = true;
} else {
elm.checked = false;
}
} else {
if (json[index] == null) {
$(elm).val("");
} else {
$("#CUST_BIC").val(json.CUST_BIC);
$("#CUST_ACCOUNT").val(json.CUST_ACCOUNT);
//$(elm).val(json[index]);
}
}
}
}
}
}
}
//表单元素自动赋值
function TransferLHMToField1(json) {
if (json) {
for ( var index in json) {
var elm = document.getElementById(index);
if (elm) {
if ("SELECT" == elm.nodeName) {
$("#CUST_BIC1").val(json.CUST_BIC);
$("#CUST_ACCOUNT1").val(json.CUST_ACCOUNT);
//$(elm).val(json[index]);
} else if ("INPUT" == elm.nodeName) {
if ("radio" == elm.type) {
$("input:radio[id='CUST_BIC1'][value='"+ json.CUST_ACCOUNT + "']").attr("checked", true);
$("input:radio[id='CUST_ACCOUNT1'][value='"+ json.CUST_ACCOUNT + "']").attr("checked", true);
} else if ("checkbox" == elm.type) {
if (elm.value == json[index]) {
elm.checked = true;
} else {
elm.checked = false;
}
} else {
if (json[index] == null) {
$(elm).val("");
} else {
$("#CUST_BIC1").val(json.CUST_BIC);
$("#CUST_ACCOUNT1").val(json.CUST_ACCOUNT);
//$(elm).val(json[index]);
}
}
}
}
}
}
}
function validator()
{
$('#thisForm').data('bootstrapValidator').validate();
var result = $('#thisForm').data('bootstrapValidator').isValid();
return result;
}
function save1(method) {
if(!validator())
{
return;
}
var param = $("#thisForm1").serialize();
ajax('sysis',method,param);
}
function rm1(method) {
if(!validator())
{
return;
}
var param = $("#thisForm1").serialize();
ajax('sysis',method,param);
}
function save(method) {
if(!validator())
{
return;
}
var param = $("#thisForm").serialize();
ajax('sysis',method,param);
}
function rm(method) {
if(!validator())
{
return;
}
var param = $("#thisForm").serialize();
ajax('sysis',method,param);
}
function ajax(qdf,method,param)
{
$.ajax({
url:'${pageContext.request.contextPath}/'+qdf+'/'+method+'.action?&time='+new Date().getTime(),
type:'POST',
data:param,
dataType:'json',
async: false,
success:function(result)
{
resetForm();
resetForm1();
$("#mytable").bootstrapTable('refresh');
$("#mytable1").bootstrapTable('refresh');
}
});
}
//重置表单
function resetForm() {
$("#thisForm").data('bootstrapValidator').destroy();
$('#thisForm').data('bootstrapValidator', null);
PageLoader.initFormValidator();
$("#mytable").bootstrapTable('uncheckAll');
$("#thisForm")[0].reset();
$("#CUST_BIC").removeAttr("readonly");
$("#CUST_ACCOUNT").removeAttr("readonly");
}
//重置表单
function resetForm1() {
$("#thisForm1").data('bootstrapValidator').destroy();
$('#thisForm1').data('bootstrapValidator', null);
PageLoader.initFormValidator1();
$("#mytable1").bootstrapTable('uncheckAll');
$("#thisForm1")[0].reset();
$("#CUST_BIC1").removeAttr("readonly");
$("#CUST_ACCOUNT1").removeAttr("readonly");
}
function getNowFormatDate() {
var date = new Date();
var seperator1 = "-";
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1
+ strDate
return currentdate;
}
</script>
</head>
<body>
<ul id="myTab" class="nav nav-tabs">
<li>
<a href="#sheet" data-toggle="tab">SYSISQF维护</a>
</li>
<li id="b">
<a href="#sheet1" data-toggle="tab">SYSISQD维护</a>
</li>
</ul>
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade in active" id="sheet1">
<div style="width: 49%; height: 100%; float: left;">
<table>
<tr>
<td valign="top" width="50%"><table id="mytable"></table></td>
<td valign="top">
<form id="thisForm">
<table style="margin-left: 20px">
<tr>
<td><font color="red">*</font>BIC</td>
<td>
<div class="col-xs-8 form-group">
<input type="text" class="form-control" id="CUST_BIC"
name="CUST_BIC" width="20" readonly/>
</div>
</td>
</tr>
<tr>
<td>分账号</td>
<td>
<div class="col-xs-8 form-group">
<input type="text" class="form-control" id="CUST_ACCOUNT"
name="CUST_ACCOUNT" readonly/>
</div>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<button type="button" class="btn" onclick="resetForm()">重置</button>
<button type="button" class="btn" onclick="save('sysisqdSave')">保存</button>
<button type="button" class="btn" onclick="rm('sysisqdDelete')">删除</button>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</div>
</div>
<div class="tab-pane fade in active" id="sheet">
<div style="width: 49%; height: 100%; float: left;">
<table>
<tr>
<td valign="top" width="50%"><table id="mytable1"></table></td>
<td valign="top">
<form id="thisForm1">
<table style="margin-left: 20px">
<tr>
<td><font color="red">*</font>BIC</td>
<td>
<div class="col-xs-8 form-group">
<input type="text" class="form-control" id="CUST_BIC1"
name="CUST_BIC1" width="20"/>
</div>
</td>
</tr>
<tr>
<td>分账号</td>
<td>
<div class="col-xs-8 form-group">
<input type="text" class="form-control" id="CUST_ACCOUNT1"
name="CUST_ACCOUNT1"/>
</div>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<button type="button" class="btn" onclick="resetForm1()">重置</button>
<button type="button" class="btn" onclick="save1('sysisqfSave')">保存</button>
<button type="button" class="btn" onclick="rm1('sysisqfDelete')">删除</button>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
controller 代码:
package com.topsoft.cbfix.ctrl;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.topsoft.cbfix.service.common.SysisService;
import com.topsoft.cbfix.util.Message;
@Controller
@RequestMapping("/sysis")
public class SysisCtrl {
@SuppressWarnings("rawtypes")
@Inject
private SysisService sysisService;
@SuppressWarnings("unchecked")
@ResponseBody
@RequestMapping("/sysisqf")
public List<Map<String, Object>> findAllQF()
{
return sysisService.findAllQF();
}
@SuppressWarnings("unchecked")
@ResponseBody
@RequestMapping("/sysisqd")
public List<Map<String, Object>> findAllQD()
{
return sysisService.findAllQD();
}
/*@ResponseBody
@RequestMapping("/sysisqdSave")
public void insert(SysisQD sysisqd)
{
sysisService.insert(sysisqd);
}*/
@ResponseBody
@RequestMapping("/sysisqdSave")
public Message saveqd(HttpServletRequest request)
{
boolean result = false;
try
{
sysisService.saveqd(request);
result = true;
}
catch(Exception e)
{
}
Message msg = new Message();
msg.setFlag(result ? "success" : "fail");
msg.setMsg(result ? "保存成功" : "保存失败");
return msg;
}
@ResponseBody
@RequestMapping("/sysisqfSave")
public Message saveqf(HttpServletRequest request)
{
boolean result = false;
try
{
sysisService.saveqf(request);
result = true;
}
catch(Exception e)
{
}
Message msg = new Message();
msg.setFlag(result ? "success" : "fail");
msg.setMsg(result ? "保存成功" : "保存失败");
return msg;
}
@ResponseBody
@RequestMapping("/sysisqdDelete")
public Message deleteqd(HttpServletRequest request)
{
boolean result = false;
try
{
sysisService.deleteqd(request);
result = true;
}
catch(Exception e)
{
}
Message msg = new Message();
msg.setFlag(result ? "success" : "fail");
msg.setMsg(result ? "保存成功" : "保存失败");
return msg;
}
@ResponseBody
@RequestMapping("/sysisqfDelete")
public Message deleteqf(HttpServletRequest request)
{
boolean result = false;
try
{
sysisService.deleteqf(request);
result = true;
}
catch(Exception e)
{
}
Message msg = new Message();
msg.setFlag(result ? "success" : "fail");
msg.setMsg(result ? "保存成功" : "保存失败");
return msg;
}
/*@ResponseBody
@RequestMapping("/sysisqdSave")
public void save(HttpServletRequest request)
{
// 国家代码
String CUST_BIC = request.getParameter("CUST_BIC");
// 国家全称(英文)
String CUST_ACCOUNT = request.getParameter("CUST_ACCOUNT");
SysisQd sysisQD = new SysisQd();
sysisQD.setCust_bic(CUST_BIC);
sysisQD.setCust_account(CUST_ACCOUNT);
sysisService.saveOrUpdate(sysisQD);
}*/
}
service代码:
package com.topsoft.cbfix.service.common;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.topsoft.cbfix.dao.BaseDAO;
@Service("sysis")
public class SysisService<V, K> {
@Autowired
private BaseDAO baseDao;
//QF查询
@SuppressWarnings("unchecked")
public List<Map<String,Object>> findAllQF()
{
return baseDao.findBySqlMap("SELECT CUST_BIC,CUST_ACCOUNT FROM SYSISQF");
}
//QD查询
@SuppressWarnings("unchecked")
public List<Map<String,Object>> findAllQD()
{
return baseDao.findBySqlMap("SELECT CUST_BIC,CUST_ACCOUNT FROM SYSISQD");
}
//QD修改or增加
public void saveqd(HttpServletRequest request){
String sql ="";
//BIC
String CUST_BIC = request.getParameter("CUST_BIC");
//分账号
String CUST_ACCOUNT = request.getParameter("CUST_ACCOUNT");
sql="SELECT CUST_BIC,CUST_ACCOUNT FROM SYSISQD where CUST_BIC='"+CUST_BIC+"' OR CUST_ACCOUNT='"+CUST_ACCOUNT+"'";
int executeSqlUpdate = baseDao.executeSqlUpdate(sql);
System.out.println(executeSqlUpdate);
if(executeSqlUpdate==0){
sql="INSERT INTO SYSISQD (CUST_BIC, CUST_ACCOUNT) VALUES ('"+CUST_BIC+"','"+ CUST_ACCOUNT+"')";
baseDao.executeSqlUpdate(sql);
}else{
sql="UPDATE SYSISQD SET CUST_BIC = '"+CUST_BIC+"',CUST_ACCOUNT='"+CUST_ACCOUNT+"' WHERE CUST_BIC = '"+CUST_BIC+"',CUST_ACCOUNT='"+CUST_ACCOUNT+"'";
baseDao.executeSqlUpdate(sql);
}
}
//QF修改or增加
public void saveqf(HttpServletRequest request){
String sql ="";
//BIC
String CUST_BIC = request.getParameter("CUST_BIC1");
//分账号
String CUST_ACCOUNT = request.getParameter("CUST_ACCOUNT1");
sql="SELECT CUST_BIC,CUST_ACCOUNT FROM SYSISQF where CUST_BIC='"+CUST_BIC+"' OR CUST_ACCOUNT='"+CUST_ACCOUNT+"'";
int executeSqlUpdate = baseDao.executeSqlUpdate(sql);
System.out.println(executeSqlUpdate);
if(executeSqlUpdate==0){
sql="INSERT INTO SYSISQF (CUST_BIC, CUST_ACCOUNT) VALUES ('"+CUST_BIC+"','"+ CUST_ACCOUNT+"')";
baseDao.executeSqlUpdate(sql);
}else{
sql="UPDATE SYSISQF SET CUST_BIC = '"+CUST_BIC+"',CUST_ACCOUNT='"+CUST_ACCOUNT+"' WHERE CUST_BIC = '"+CUST_BIC+"',CUST_ACCOUNT='"+CUST_ACCOUNT+"'";
baseDao.executeSqlUpdate(sql);
}
}
//QD删除
public void deleteqd(HttpServletRequest request){
String sql ="";
//BIC
String CUST_BIC = request.getParameter("CUST_BIC");
//分账号
String CUST_ACCOUNT = request.getParameter("CUST_ACCOUNT");
sql="DELETE FROM SYSISQD where CUST_BIC='"+CUST_BIC+"' AND CUST_ACCOUNT='"+CUST_ACCOUNT+"'";
baseDao.executeSqlUpdate(sql);
}
//QF删除
public void deleteqf(HttpServletRequest request){
String sql ="";
//BIC
String CUST_BIC = request.getParameter("CUST_BIC1");
//分账号
String CUST_ACCOUNT = request.getParameter("CUST_ACCOUNT1");
sql="DELETE FROM SYSISQF where CUST_BIC='"+CUST_BIC+"' AND CUST_ACCOUNT='"+CUST_ACCOUNT+"'";
baseDao.executeSqlUpdate(sql);
}
}