Skip to content
Snippets Groups Projects
RequestController.java 1.01 KiB
Newer Older
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="/request") // This means URL's start with /demo (after Application path)
public class RequestController {
    @Autowired // This means to get the bean called userRepository
    // Which is auto-generated by Spring, we will use it to handle the data
    private ReqRepository reqRepository;


    @PostMapping(path = "/add") // Map ONLY POST Requests
    @ResponseBody
    public Request addJsonOrg(@RequestBody Request req) {
        // @ResponseBody means the returned String is the response, not a view name
        // @RequestParam means it is a parameter from the GET or POST request
        reqRepository.save(req);
        return req;
    }

}