前端:form多个字段传递给后台,保存至数据库。(序列化form表单内容)

serializeArray() 方法通过序列化表单值来创建对象数组(名称和值)。 

传给后台:

 后台接收:

1、python形式

 # 添加公告
    @staticmethod
    def add_notice(request):
        data = {}
        data = json.loads(request.body.decode()) #  将json格式数据转换为字典
        data["notice_id"] = idCreater.appKeyWorker.get_id()
        data["create_time"] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        print(data)
        Notice.objects.create(**data)
        return JsonResponse({"state": 200, "msg": "success"}, json_dumps_params={'ensure_ascii': False})

 

2、Java形式 

 

 

    @PostMapping("/addUser")
    @Transactional()
    public Object addUser(@RequestBody UsersEntity user){
        Result result = new Result();
        String otp = webSMSRedis.get(user.getPhone());

        if (EmptyUtils.isEmpty(otp)){
            result.setCode(1);
            result.setMsg("验证码已过期,请重新获取!");
            return result;
        }
        if (!otp.equals(user.getsMSCode())){
            result.setCode(1);
            result.setMsg("验证码错误,请重新输入!");
            return result;
        }
        if (webUsersService.insertUser(user)>0){
            result.setCode(0);
            result.setMsg("注册成功");
            return result;
        }
        result.setCode(1);
        result.setMsg("注册失败,请稍后再试试");
        return result;
    }

 

你可能感兴趣的:(Python,java,JQ,javascript,python,java)