package com.example.accessingdatamysql; import org.apache.coyote.Response; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import java.util.Map; import java.util.Optional; @CrossOrigin @RestController // This means that this class is a Controller @RequestMapping(path="/organization") // This means URL's start with /demo (after Application path) public class OrgController { @Autowired // This means to get the bean called userRepository // Which is auto-generated by Spring, we will use it to handle the data private OrgRepository orgRepository; @PostMapping(path = "/add") // Map ONLY POST Requests @ResponseBody public Organization addJsonOrg(@RequestBody Organization org) { // @ResponseBody means the returned String is the response, not a view name // @RequestParam means it is a parameter from the GET or POST request orgRepository.save(org); return org; } @GetMapping(path="/all") public @ResponseBody Iterable<Organization> getAllOrgs() { // This returns a JSON or XML with the users return orgRepository.findAll(); } }