Home  >  Q&A  >  body text

How to integrate Angular application with MySQL database?

I'm writing my first Angular application, but don't know how to integrate it with a MySQL database.

This is a method in the controller:


@GetMapping(value = "/{employeeId}")
public Employee findEmployeeById(@PathVariable Long employeeId) {
    return employeeService.getById(employeeId);
}

A fragment of 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 and Spring applications both start, but only show a blank page on localhost:4200. The @CrossOrigin(origins = "http://localhost:4200") annotation has been added.

P粉613735289P粉613735289429 days ago488

reply all(1)I'll reply

  • P粉729518806

    P粉7295188062023-07-21 12:45:33

    The best way is to create a REST API and send requests to the backend via POST request or GET request. You should run Node.js on another port and request your data.

    reply
    0
  • Cancelreply