Spring Delete Mapping

[Solved] Spring Delete Mapping | Solidity - Code Explorer | yomemimo.com
Question : spring delete mapping

Answered by : lucas-pauw9cuw3gol

package com.zetcode.controller;
import com.zetcode.model.Post;
import com.zetcode.service.IPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import java.util.Set;
import static org.springframework.http.ResponseEntity.ok;
@Controller
@RequestMapping("/posts")
public class MyController { @Autowired private IPostService postService; @GetMapping public ResponseEntity<Set<Post>> all() { return ok().body(postService.all()); } @DeleteMapping("{id}") public ResponseEntity<Long> deletePost(@PathVariable("id") Long id) { var isRemoved = postService.delete(id); if (!isRemoved) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } return new ResponseEntity<>(id, HttpStatus.OK); }
}

Source : http://zetcode.com/spring/deletemapping/ | Last Update : Wed, 28 Oct 20

Answers related to spring delete mapping

Code Explorer Popular Question For Solidity