java - Java数据类型到Typescript类型

标签 java angular typescript

我正在尝试在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/

相关文章:

javascript - 导入组件自带的模块

TypeScript:条件泛型类型作为不可分配的函数返回值

Angular |将服务注入(inject)装饰器

java - 从连接池中释放连接

java - 使用匿名类有什么害处?

angular - 能够禁用 primeNG 编辑器框

angular - 如何在 angular2 中模拟 @Input() 对象?

java - 开发中如何避免在编译时浪费时间?

java - Spring、Hibernate、JPA、ManyToOne 添加了 where 子句或 Differentiator 列,但没有继承

typescript - 元素隐式具有 'any' 类型,因为在 typescript 中将字符串转换为枚举时,索引表达式不是枚举的 'number' 类型