我正在做這個專案,該專案是由其他人發起的。模型檔案夾def 和 dto中有兩個介面檔案。我不清楚def 和 dto 介面檔案之間的區別。任何有經驗的開發人員都可以讓我知道有什么區別以及何時以及如何使用dto而不是def,反之亦然。提前致謝。
供應商-def.interface.ts:
import { SourceType, VendorType } from '../shared/enums/vendor-type.enum';
export interface VendorDef {
vendorId: string;
companyCode: string;
name: string;
acronym: string;
alias: string;
legalId: string;
vendorType: VendorType;
sourceType: SourceType;
fiscalCode: string;
}
export interface VendorFormDef {
sourceType: SourceType;
companyCode?: string;
previousMainCompany?: string;
}
export interface InUsageDef {
acronym: boolean;
legalId: boolean;
fiscalCode: boolean;
}
供應商-dto.interface.ts
import { SourceType, VendorType } from '../shared/enums/vendor-type.enum';
export interface VendorDto {
data: VendorDataDto[] | VendorDataDto;
errors?: VendorErrorsDto;
}
export interface VendorDataDto {
attributes: VendorAttributesDto;
id: string;
}
export interface VendorErrorsDto {
code: string;
title: string;
detail: string;
}
export interface VendorCreateDto {
companyCode: string;
name: string;
acronym: string;
legalId: string;
fiscalCode: string;
vendorType: VendorType;
sourceType: SourceType;
}
uj5u.com熱心網友回復:
基本上,它用于將您的 API 提供給您的內容與您將操作的物件分開。
VendorDTO是您的 API 回應(因此存在dataanderrors欄位)VendorDef是您將在應用程式中操作的物件的定義。
當您請求資料時,通常會有一個轉換器 from VendorDTOto for ,而當您想要在 API 上推送添加/更新時,通常會有一個轉換器 from to。VendorDefVendorDefVendorDTO
它不限于 Typescript 或 Angular,因此您可能需要檢查問題的標簽。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/487483.html
標籤:javascript 有角度的 打字稿
