简体   繁体   English

Angular 中的关系(错误 400 - 错误请求)

[英]Relations in Angular (Error 400 - Bad Request)

I have quite a big problem with adding data to the table connected with the Spring database.我在向与 Spring 数据库连接的表中添加数据时遇到了很大的问题。 Namely, just adding to the table works fine, only when I don't choose anything from the Combo Box.也就是说,仅添加到表格中效果很好,只有当我不从组合框中选择任何内容时。 When I choose, I get this message:当我选择时,我收到以下消息:

zone-evergreen.js:2952 POST http://localhost:4200/api/cars 400 (Bad Request)

HttpErrorResponse {headers: HttpHeaders, status: 400, statusText: "Bad Request", url: "http://localhost:4200/api/cars", ok: false, …}

I am aware that this is a problem with the link and most likely with a relationship, but I have no idea how to solve this problem.我知道这是链接问题,很可能是关系问题,但我不知道如何解决这个问题。 My models look like this:我的模型看起来像这样:

http-cars.model.ts http-cars.model.ts

export class carStatus {
  id: number;
  name: string;
}

//carStatus.model.ts (TypeScript)

export class carType {
  id: number;
  name: string;
}

//carType.model.ts (TypeScript)

To better understand the problem, I will give services and the vehicle adding component (if you need more files, please write):为了更好地理解问题,我将提供服务和车辆添加组件(如果您需要更多文件,请写):

add-dialog1.component.ts add-dialog1.component.ts

http-cars.service.ts http-cars.service.ts

car-status.service.ts (carType has the same service only with changed variables and names) car-status.service.tscarType具有相同的服务,只是改变了变量和名称)

config.service.ts (all included functions link to a link from proxy.conf.json) config.service.ts (所有包含的函数都链接到来自 proxy.conf.json 的链接)

{
  "/api": {
    "target": "xxx(link)",
    "secure": false,
    "changeOrigin": true,
    "logLevel": "debug"
  }

}

And finally HTML:最后是 HTML:

add-dialog1.component.html add-dialog1.component.html

If anyone has an idea why adding data without using a combo box works fine, and if I choose something from these two combo boxes (or one of them) the above error appears, please write what I made the error and how I can solve it.如果有人知道为什么在不使用组合框的情况下添加数据可以正常工作,并且如果我从这两个组合框(或其中一个)中选择某些内容,则会出现上述错误,请写出我犯的错误以及如何解决它. Buddy responsible for Spring said that everything is fine on his part and when he sends data via Postman it works for him, but in my table in combobox columns shows "[object object]".负责 Spring 的 Buddy 说他的一切都很好,当他通过 Postman 发送数据时,它对他有用,但在我的表格中的组合框列中显示“[对象对象]”。 here is an example of a query and part of my table:这是一个查询示例和我的表的一部分:

Postman Query邮递员查询

Part of table表的一部分

Please be forgiving.请原谅。 This is my second question and I have no experience asking questions here, and I am mostly looking for answers on this page.这是我的第二个问题,我没有在这里提问的经验,我主要是在这个页面上寻找答案。 If I did something incompatible with your netiquette, please let me know.如果我做了与您的网络礼节不符的事情,请告诉我。 I can't find any solution to the problem and what I tried didn't work and I need help.我找不到问题的任何解决方案,我尝试的方法无效,我需要帮助。

I would start by looking at the information available in the "network" tab, usually in the console window or menu of your browser.我会首先查看“网络”选项卡中可用的信息,通常在控制台窗口或浏览器菜单中。

Second, I would attempt to issue the command to the backend using a curl command.其次,我会尝试使用 curl 命令向后端发出命令。 The ability to do that would tell you whether the problem is in your frontend or backend or http command.这样做的能力会告诉您问题是在您的前端还是后端或 http 命令中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM