Перенос HTTP-сообщения со строкой, целочисленным телом в spring boot

#spring-boot #flutter #dart #http-post

#spring-boot #flutter #dart #http-post

Вопрос:

Не удается выполнить post запрос со статическими пользователями из моего приложения flutter в мой Spring-boot rest api

мой контроллер

 @PostMapping("/user/create")

public HashMap<String, Object>createbody(@Valid @RequestBody User users){

    LOGGER.info("controller hit");

    try {
        userRepository.save(users);  
    }catch (Exception e) {
        return ReturnsMap(1, e.getMessage(), null);
    }

    return ReturnsMap(0, "User created", users);        
}
  

Код Flutter

 Future<int>  registerUser() async {
    Map<String, string> body = Map();
    body['nick_name'] = "anu";
    body['user_profile_id'] = "123";

    final response = await http.post(
        postURL,  
        headers: <String, String>{
            'Content-Type': 'application/json',
        },

        body: json.encode(body)
    );

    //print(body);

    if (response.statusCode == 200) {
        print("success");
        return 0;
    } else {
      throw Exception('Failed to registration');      
    }
}
  

Ответ №1:

 Map<String, string> body = Map();
body['nick_name'] = "anu";
body['user_profile_id'] = "123";
var response = await http.post(postURL,  body: body);