So when I visit an enpoint(POST request), I first check if an entry already exists in my database. If yes, I want to return it to the user (for tracking purposes) and continue an operation. But I would like to return the id to the user and continue this process. How to achieve this??
@RestController
public class StudentController {
@Autowired
private StudentService service;
@PostMapping("/storeInDB")
@ResponseBody
public File_Tracking saveStudentDetails(@RequestBody Student student ) throws IOException {
List<Students> student = new ArrayList<>();
int continue = 0;
int id = 0;
id = service.getId(); // I want to return this and continue some other process which follows
You can run the process asychronously in a different thread ,while your main thread returns the id as the service response.
Check this blog about how to define Async operations using spring @Async annotation https://www.baeldung.com/spring-async
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With