Я пытаюсь понять, как обрабатывать пост-запросы весной с json -информацией. Но у меня возникло ощущение, что я что-то упустил. Я предполагаю, что я не должен использовать RequestParam в пост-запросе, но я не понимаю, как получить доступ к значениям тела.
Backend
@CrossOrigin(origins = "http://localhost:3000")
@PostMapping(path = "api/delete", consumes = "application/json", produces = "application/json")
@ResponseBody
public String delete(@RequestParam("filename") String filename) throws IOException {
String filePath = imageFolder + filename;
File file = new File(filePath);
logger.info(filePath);
if(file.delete())
{
return "{\"success\":1}";
}
else
{
return "{\"fail\":1}";
}
}
Frontend
const deleteImage = () => {
const re = /images\/(.+)$/;
const filePath = imageUrl.match(re);
const url = `http://localhost:8080/api/delete/`
const data = {filename:filePath}
const options = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: data
};
fetch(url, options);
};