[英]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 (技术和日期),我如何在浏览器上运行这些查询
我的 interfaceDao 是:
public interface employesDao extends JpaRepository <employes, Integer>{
public List<employes>findByNomContains(Date date);
@SuppressWarnings("rawtypes")
public List<employes>findByNomContains(List<List> techno);
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;
}
}
如果您想立即访问此端点,您可以尝试使用 REST 客户端(例如 Postman 或 YARC)而不是浏览器来尝试POST http://localhost:8080/api/Addemployes
。 否则,您需要开发一个与之交互的表单(首先创建员工,然后调用POST /api/Addemployes
employe
)。
作为一般性评论,我不会调用端点Addemployes
,但与GET
端点相同。 仅 REST 规则就让用户了解POST
将创建一个新实体。 此外,例如,使用像 SonarLint 这样的代码 linter,您的语法不是标准的,这些工具可以让您实时知道出了什么问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.