모 HttpErrorResponse GET 요청

0

질문

저는 간단하 Quarkus 프로젝트 및 보여주고 싶은 데이터에서는 각 테이블 HttpClient. 나는 또한 CORS 필터입니다. 어쨌든,다음과 같은 오류가: 각도 없는 테이블에 날짜,HttpErrorResponse 상태 0

서비스입니다.ts

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { School } from './model/school';

@Injectable({
  providedIn: 'root'
})
export class SchoolService {

  url = "localhost:8080/school"

  constructor(public http: HttpClient) { }

  getAll(): Observable<School[]> {
    return this.http.get<School[]>(this.url);
  }

  getById(id: number): Observable<School> {
    const url = "locahlost:8080/school/{id}";
    return this.http.get<School>(url);
  }

}

ts 의 구성요소

import { Component, OnInit } from '@angular/core';
import { School } from '../model/school';
import { SchoolService } from '../school.service';

@Component({
  selector: 'app-dashboard',
  templateUrl: './dashboard.component.html',
  styleUrls: ['./dashboard.component.css']
})
export class DashboardComponent implements OnInit {

  schools: School[] = [];
  
  constructor(public schoolService: SchoolService) { }

  ngOnInit(): void {
    this.schoolService.getAll().subscribe(e => {
      this.schools = e;
    });
  }

}

html

<table>
    <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Street</th>
        </tr>
    </thead>
    <tbody>
        <tr *ngFor="let school of schools">
            <td>{{school.id}}</td>
            <td>{{school.name}}</td>
            <td>{{school.street}}</td>
        </tr>
    </tbody>
</table>

서버 모델

package model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class School {

    @Id
    @GeneratedValue
    private int id;
    private String name;
    private String street;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }
}

리소스

package rest;

import model.School;

import javax.inject.Inject;
import javax.transaction.Transactional;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.List;

@Path("school")
@Produces(MediaType.APPLICATION_JSON)
@Transactional
public class SchoolResource {

    @Inject
    SchoolDao dao;

    @GET
    public List<School> getAll() {
        return dao.getAll();
    }

    @Path("id")
    @GET
    public School getById(@PathParam("id") int id) {
        return dao.getById(id);
    }

}

dao

package rest;

import model.School;

import javax.enterprise.context.Dependent;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import java.util.List;

@Dependent
public class SchoolDao {

    @Inject
    EntityManager em;

    public List<School> getAll() {
        return em.createQuery("select s from School s", School.class).getResultList();
    }

    public School getById(int id) {
        return em.find(School.class, id);
    }

}

사전에 감사합니다,나는 생각한 문제 서버에 있어야 합니다,려 했기 때문에 보여주는 데이터 JSON 파일 대신 Quarkus 데이터미,그리고 작업을 수행합니다.

angular httpclient java rest
2021-11-24 00:14:07
1

최고의 응답

0

@R.Richards 언급 에 코멘트를 넣어,"http://"앞에서 url 이 서비스에서 파일 문제를 해결했다.

2021-11-24 06:44:38

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................