I'm new to spring boot i'm developing a spring boot application to manage the employees, and i'm in the database stage, in my control I've added a SQL query that allows to select the employees compared to a base field (techno and date), how can I run these queries on a browser
My interfaceDao is:
public interface employesDao extends JpaRepository <employes, Integer>{
public List<employes>findByNomContains(Date date);
@SuppressWarnings("rawtypes")
public List<employes>findByNomContains(List<List> techno);
the controller
@RestController
@RequestMapping("/api")
public class employesController {
@Autowired
employesDao employestdao;
// Affiche la liste de tous les employes dans la base
@GetMapping(value = "/employes")
public List<employes> listeDesemployes(){
List<employes> employes = employesdao.findAll();
if(employes.isEmpty()) throw new ProductNotFoundException("Aucun employes n'est enregistréer dans la base");
return employes;
}
//Ajouter un employes
@PostMapping(value = "/Addemployes")
public employes ajouterProduit(@RequestBody employes employes) {
employes employesAdded = employesdao.save(employes);
return employesAdded;
}
}
You can probably try POST http://localhost:8080/api/Addemployes
using a REST client (Postman or YARC for example) instead of a browser if you want to access this endpoint right away. Otherwise you need to develop a form to interact with it (creating the employe
first then calling the POST /api/Addemployes
endpoint).
As a general comment, I would not call the endpoint Addemployes
but just the same as the GET
endpoint. REST rules alone let the user understand that a POST
will create a new entity. Also, use a code linter like SonarLint for example, your syntax is not standard and such tools let you know in real time what is wrong.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.