目录

vue-前端向Java后端发送字符串数组

vue 前端向Java后端发送字符串数组

// 这是前端vue发送的axios请求 

saveEditForm(val) {
      console.log(val, "val****")
      // let email = Qs.stringify(val.email)
      // let id = Qs.stringify(val.id)
      // let nickName = Qs.stringify(val.nickName)
      // let phoneNum = Qs.stringify(val.phoneNum)
      // let roles = Qs.stringify(val.roles)

      this.$http
        .post(
          "/admin/updateUerInfo",
          Qs.stringify({
            id: val.id,
            email: val.email,
            nickName: val.nickName,
            phoneNum: val.phoneNum,
            roles: JSON.stringify(val.roles)
          })
        )
        .then(response => {
          console.log(response.data.data)
        })
}

Java 后端接收前端发来的数据   数组字段为:(String roles)

数据样式:

/**
     * @param
     * @return
     * @Description 更新用户信息及修改用户角色
     */

    @PostMapping("/admin/updateUerInfo")
    @ResponseBody
    public ResultResponse updateUerInfo(String id, String email, String nickName, String phoneNum, String roles) {

        List<Role> roleList = JSONObject.parseArray(roles, Role.class);
        List<Long> roleIdList = roleList.stream().map(role -> role.getId()).collect(Collectors.toList());

        // 修改用户的角色
        iUserService.updateUserRole(roleIdList);
        // 修改用户信息
        iUserService.updateUerInfo(id, email, nickName, phoneNum);

        return null;
    }

最终变成想要的样子了

https://i-blog.csdnimg.cn/blog_migrate/c55329814475466d1ace999508046a09.png