Jak używać postman i jak powinna wyglądać metoda żeby przyjęła wartosci

0

Mam pytanie odnośnie metody i Postman. Domyślam się że to podstawy ale nie mogę sobie z tym poradzić . Chciałbym żeby metoda przyjmowała dane z POSTMAN i zapisywała je do bazy.

@RequestMapping(value = "/create")
  @ResponseBody
  public String create(String email, String name) {
    User user = null;
    try {
      user = new User(email, name);
      userDao.save(user);
    }
    catch (Exception ex) {
      return "Error creating the user: " + ex.toString();
    }
    return "User succesfully created! (id = " + user.getId() + ")";
  }

I jak zabrać się od strony Postman żeby wstawić te dane
POST localhost:8080/create

{
"email":"[email protected]",
"name":"test"
}

W tej chwili mam tak jak wyżej ale dostaję błąd

Error creating the user: javax.validation.ConstraintViolationException: Validation failed for classes [com.java.api.model.User] during persist time for groups [javax.validation.groups.Default, ]
List of constraint violations:[
	ConstraintViolationImpl{interpolatedMessage='may not be null', propertyPath=email, rootBeanClass=class com.java.api.model.User, messageTemplate='{javax.validation.constraints.NotNull.message}'}
	ConstraintViolationImpl{interpolatedMessage='may not be null', propertyPath=name, rootBeanClass=class com.java.api.model.User, messageTemplate='{javax.validation.constraints.NotNull.message}'}
]
0

Twoja metoda nie wie, że ma przyjmować dwa argumenty przy requeście HTTP i dlatego wywołujesz ją z dwoma nullami. Poczytaj o @PathVariable, @RequestBody, @RequestParam

0

dziekuje za odp.

1 użytkowników online, w tym zalogowanych: 0, gości: 1