jQuery-使用-用jquery的ajax进行前端传输数据到后端实现保存数据的做法

注意:环境都以搭好,这只是粗浅的表现实现代码而已
//其中,RESV_BILLING_HOUR_FOUR等字段是html中某个标签的id
前端:


后端

@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 configs = configRepository.findConfigsByInstrumentUid(insUid);
        Config config = null;
        ConfigMachine configMachine=null;
        if(configs.size() != 0){
            config = configs.get(0);
            List 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";
    }

你可能感兴趣的:(jQuery-使用-用jquery的ajax进行前端传输数据到后端实现保存数据的做法)