注意:环境都以搭好,这只是粗浅的表现实现代码而已
//其中,RESV_BILLING_HOUR_FOUR等字段是html中某个标签的id
前端:
<script>
//保存计费管理的设置
function saveConfig(){
//保存计费时长
var RESV_BILLING_HOUR;
if(RESV_BILLING_HOUR_FOUR.checked){
RESV_BILLING_HOUR="RESV_BILLING_HOUR_FOUR";
}
if(RESV_BILLING_HOUR_THREE.checked){
RESV_BILLING_HOUR="RESV_BILLING_HOUR_THREE";
}
if(RESV_BILLING_HOUR_TWO.checked){
RESV_BILLING_HOUR="RESV_BILLING_HOUR_TWO";
}
if(RESV_BILLING_HOUR_ONE.checked){
RESV_BILLING_HOUR="RESV_BILLING_HOUR_ONE";
}
//是否要分段
var isBillingSeg;
if(isBillingSegYes.checked){
isBillingSeg=true;
}
if(isBillingSegNo.checked){
isBillingSeg=false;
}
//收费流程
var AuditOne;
if(isAuditOne.checked){
AuditOne=true;
}else{
AuditOne=false;
}
var AuditTwo;
if(isAuditTwo.checked){
AuditTwo=true;
}else{
AuditTwo=false;
}
var AuditThree;
if(isAuditThree.checked){
AuditThree=true;
}else{
AuditThree=false;
}
var AuditFour;
if(isAuditFour.checked){
AuditFour=true;
}else{
AuditFour=false;
}
var insUid1=insUid.value;
var myData={
"RESV_BILLING_HOUR":RESV_BILLING_HOUR,
"isBillingSeg":isBillingSeg,
"AuditOne":AuditOne,
"AuditTwo":AuditTwo,
"AuditThree":AuditThree,
"AuditFour":AuditFour,
"insUid":insUid1
}
$.ajax({
url:"../config/saveConfigMachineBilling",
type:'POST',
async:false,
data:myData,
success:function(data){//AJAX查询成功
if(data=="success"){
alert("修改成功!");
}else{
alert("修改失败!");
}
}
});
}
</script>
后端
@ResponseBody
@RequestMapping("/saveConfigMachineBilling")
public String saveConfigMachineBilling(HttpServletRequest request){
//获取所有变量
String RESV_BILLING_HOUR=request.getParameter("RESV_BILLING_HOUR");
String isBillingSeg=request.getParameter("isBillingSeg");
String AuditOne=request.getParameter("AuditOne");
String AuditTwo=request.getParameter("AuditTwo");
String AuditThree=request.getParameter("AuditThree");
String AuditFour=request.getParameter("AuditFour");
String insUid=request.getParameter("insUid");
List<Config> configs = configRepository.findConfigsByInstrumentUid(insUid);
Config config = null;
ConfigMachine configMachine=null;
if(configs.size() != 0){
config = configs.get(0);
List<ConfigMachine> configMachines = configMachineRepository.findConfigMachinesByConfigUid(config.getUid());
if(configMachines.size() != 0){
configMachine=configMachines.get(0);
}
}
configMachine.setBillingHourInDictionary(RESV_BILLING_HOUR);
if(AuditOne=="true"){
configMachine.setIsAuditOne("1");
}else{
configMachine.setIsAuditOne("0");
}
if(AuditTwo=="true"){
configMachine.setIsAuditTwo("1");
}else{
configMachine.setIsAuditTwo("0");
}
if(AuditThree=="true"){
configMachine.setIsAuditThree("1");
}else{
configMachine.setIsAuditThree("0");
}
if(AuditFour=="true"){
configMachine.setIsAuditFour("1");
}else{
configMachine.setIsAuditFour("0");
}
if(isBillingSeg=="true"){
configMachine.setIsBillingSeg("1");
}else{
configMachine.setIsBillingSeg("0");
}
configMachineRepository.save(configMachine);
return "success";
}