我正在尝试在Angular 8中创建一个Interface。我想为每个Json属性定义类型,并且后端使用Spring / Java。
Java Code and types:
private TestDto(
@JsonProperty("id") **String** id,
@JsonProperty("version") **long** version,
@JsonProperty("modifyDate") **Instant** modifyDate,
@JsonProperty("duration") **Duration** duration,
@JsonProperty("testValue") **Float** testValue
)
What should be in the Angular Interface?
export interface Example {
id: string;
version:
modifyDate:
duration:
testValue:
}
Thank you in advance.
最佳答案
您可以使用此Typescript生成器maven插件,而不是自己创建Typescript模型类。自动化该过程将使您免于人为错误,除了您不必一直烦恼对齐打字稿和Java方面。
<plugin>
<groupId>cz.habarta.typescript-generator</groupId>
<artifactId>typescript-generator-maven-plugin</artifactId>
<version>2.8.449</version>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
<configuration>
<jsonLibrary>jackson2</jsonLibrary>
<classPatterns>
<pattern>com.mypackage.something.**.model.*</pattern>
</classPatterns>
<outputKind>module</outputKind>
<outputFileType>implementationFile</outputFileType>
<mapEnum>asEnum</mapEnum>
<nonConstEnums>true</nonConstEnums>
<mapClasses>asClasses</mapClasses>
<mapDate>asString</mapDate>
<stringQuotes>singleQuotes</stringQuotes>
</configuration>
</plugin>
关于java - Java数据类型到Typescript类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57290830/