Jungs das Problem ist, ich bin immer den FehlerAntrag Methode ‚POST‘ nicht Feder 4
Request method 'POST' not supported
Hier ist mein Controller:
package com.mintad.spring.controllers;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.mintad.common.beans.Gouvernorate;
import com.mintad.common.service.GouvernorateService;
@RestController
@RequestMapping("/data")
public class DataController {
private static final Logger LOGGER = LogManager.getLogger(DataController.class);
@Autowired
private GouvernorateService gouvernorateService;
@RequestMapping(value = "/gouvernorates", method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<List<Gouvernorate>> getGouvernorates() throws FileNotFoundException {
return new ResponseEntity<List<Gouvernorate>>(gouvernorateService.findAll(), HttpStatus.OK);
}
@RequestMapping(value = "/addGouvernorate", method = RequestMethod.POST, produces = { "application/json" })
public @ResponseBody ResponseEntity<Gouvernorate> addGouvernorate(BindingResult result, Model model, @RequestParam(name = "name") String name,
@RequestParam(name = "delegation") String delegation, @RequestParam(name = "district") String district,
@RequestParam(name = "postalCode") String postalCode) throws IOException {
LOGGER.info("addGouvernorate called");
Gouvernorate gouvernorate = new Gouvernorate(name, delegation, district, postalCode);
gouvernorateService.addGouvernorat(gouvernorate);
return new ResponseEntity<Gouvernorate>(gouvernorate, HttpStatus.OK);
}
@RequestMapping(value = "/addTest", method = RequestMethod.POST)
public @ResponseBody String addTest(BindingResult result, Model model) {
LOGGER.info("addGouvernorate called");
Gouvernorate gouvernorate = new Gouvernorate("test", "test", "test", "test");
gouvernorateService.addGouvernorat(gouvernorate);
return "Your Professional Details Updated";
}
}
Ich habe so viele Lösungen ausprobiert, aber in vergeblich. Ich werde dankbar für jede Hilfe
http://localhost:8080/mintad/data/addTest (POST)
http://localhost:8080/mintad/data/addGouvernorate?name=test&delegation=test&district=test&postalCode=test (POST too)
:
ich die Controller-Methode bin Aufruf als Anwendung unter Verwendung von Chrom Postman folgt!
jede mögliche Hilfe bitte? – Sofiane