-
Notifications
You must be signed in to change notification settings - Fork 11
simulations v0.3
Albert edited this page Apr 25, 2024
·
7 revisions
In this lab we are going to:
- Focus on project with H2 JPA and Postman
- Test it with API Rest
- Work on @Entity

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster.
CommandLineRunner is an interface that has run() method. It is used to execute some code just after the Spring Boot application has started.
The main application should implement this interface and override its run method. In this run method, we write code like initializing our database with some value or any other logic which should be executed just after the app starts.
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
@Component
public class RunnerFillingDB implements ApplicationRunner {
@Autowired
SimulationService simulationService;
@Override
public void run(ApplicationArguments args) throws Exception {
simulationService.populate();
}
}
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Optional;
@RestController
@RequestMapping("/api/v1/simulation/")
public class SimulationRestController {
@Autowired
SimulationRepository simulationRepository;
@DeleteMapping
public String deleteSimulation(@RequestParam String id) {
//System.out.println("id:" + id);
Optional<Simulation> simulationFound = simulationRepository.findById(id);
//System.out.println("simulationFound:" + simulationFound);
if (simulationFound.isPresent()){
simulationRepository.deleteById(id);
String response = "simulation deleted: " + id;
return response;
} else return "id not found";
}
}


React - Spring Boot - API Rest - H2 DataBase - Axios - React_router_dom - JPA