我正在编写我的第一个Angular应用程序,但是不知道如何将它与MySQL数据库集成。
这是控制器中的一个方法:
@GetMapping(value = "/{employeeId}")
public Employee findEmployeeById(@PathVariable Long employeeId) {
return employeeService.getById(employeeId);
}
一个app.component.ts的片段:
constructor(private http: HttpClient) {
this.http.get<Employee>("http://localhost:8080/employees/{employeeId}").subscribe(result => {
this.employee = result;
console.log(this.employee);
});
}
Angular和Spring应用程序都启动了,但在localhost:4200上只显示一个空白页面。已添加@CrossOrigin(origins = "http://localhost:4200")注解。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
最好的方法是创建一个REST API,并通过POST请求或GET请求向后端发送请求。您应该在另一个端口上运行Node.js,并请求您的数据。