Поместите запрос с файлом и телом json - PullRequest
0 голосов
/ 05 февраля 2019

Я создаю POST Rest API с @RequestParam, и он работает с:

@PostMapping("/shop-menu")
@PreAuthorize("@accessChecker.hasAccessToWebservice(#request)")
public ResponseEntity<EntiteShopMenuDTO> addShopMenu(HttpServletRequest request,
                                                       @RequestParam("numeroLicence") String numeroLicence,
                                                       @RequestParam("ordre") Integer ordre,
                                                       @RequestParam("titre") String titre,
                                                       @RequestParam("url") String url,
                                                       @RequestParam("logo") MultipartFile logo) throws URISyntaxException, CustomException, IOException {

, и я использую Почтальон для теста:

enter image description here

Это прекрасно работает.

Теперь я хочу то же самое, но запрос PUT:

@PutMapping("/shop-menu/{numeroLicence}")
@PreAuthorize("@accessChecker.hasAccessToWebservice(#request)")
public ResponseEntity<EntiteShopMenuDTO> updateShopMenu(HttpServletRequest request,
                                                          @PathVariable String numeroLicence,
                                                          @RequestParam("test") String test,
                                                         @RequestParam(value = "logoFile", required = false) MultipartFile logoFile) throws CustomException, IOException {

И с Почтальоном попытаться:

enter image description here

И результат:

{
"type": "https://www.jhipster.tech/problem/problem-with-message",
"title": "Bad Request",
"status": 400,
"detail": "Required String parameter 'test' is not present",
"path": "/api/shop-menu/BJ3-M1",
"message": "error.http.400"
}

Я пытаюсь сделать то же самое с телом json для параметра объекта вместо параметра теста и того же результата.

СЗавиток это работает:

curl -X PUT --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' --header 'Authorization: Bearer <MY_TOKEN>' {"type":"formData"} 'http://localhost:8080/api/shop-menu/BJ3-M1?test=TOTO'

Можете ли вы помочь мне, пожалуйста?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...