[英]How should i execute a SQL query in spring boot in the browser
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 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 (技术和日期),我如何在浏览器上运行这些查询
My interfaceDao is:我的 interfaceDao 是:
public interface employesDao extends JpaRepository <employes, Integer>{
public List<employes>findByNomContains(Date date);
@SuppressWarnings("rawtypes")
public List<employes>findByNomContains(List<List> techno);
the controller 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.如果您想立即访问此端点,您可以尝试使用 REST 客户端(例如 Postman 或 YARC)而不是浏览器来尝试
POST http://localhost:8080/api/Addemployes
。 Otherwise you need to develop a form to interact with it (creating the employe
first then calling the POST /api/Addemployes
endpoint).否则,您需要开发一个与之交互的表单(首先创建员工,然后调用
POST /api/Addemployes
employe
)。
As a general comment, I would not call the endpoint Addemployes
but just the same as the GET
endpoint.作为一般性评论,我不会调用端点
Addemployes
,但与GET
端点相同。 REST rules alone let the user understand that a POST
will create a new entity.仅 REST 规则就让用户了解
POST
将创建一个新实体。 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.此外,例如,使用像 SonarLint 这样的代码 linter,您的语法不是标准的,这些工具可以让您实时知道出了什么问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.