發表文章

目前顯示的是 2月, 2020的文章

Type Script 中 如何寫 overload

在TypeScript 中視可以寫 overload TypeScript 是支援 overload但是非常奇葩 又愛又恨 可以更短的寫出來 但是我覺閱讀性卻欠佳 如下方所表示 Code Like this import { DateTimeFormatter, LocalDateTime } from "@js-joda/core" ; export class DBUtils { public static toDateString(inDateStr: string, formate : string): string; public static toDateString(inDateStr: string, formate : DateTimeFormatter): string; public static toDateString(d: Date ): string; public static toDateString(arg1: string | Date , arg2?: string | DateTimeFormatter): string { if ( typeof arg1 === 'string' && typeof arg2 === 'string' ) { let ldt: LocalDateTime = LocalDateTime.parse(arg1, DateTimeFormatter.ofPattern(arg2)); return ldt.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME); } if ( typeof arg1 === 'string' && arg2 instanceof DateTimeFormatter) { let ldt: LocalDateTime = LocalDateTime.parse(arg1, arg2);

SpringBoot 2.x Junit 起手式

每次開新專案都要找 所以來記錄一下 JUnit File 起手式 package com.dom.fycc; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @RunWith (SpringRunner.class) @SpringBootTest class YellowCalendarCacheApplicationTests { @Test void contextLoads () { assertEquals( 0 , 0 ); } } build.gradle testImplementation( 'org.springframework.boot:spring-boot-starter-test' ) { exclude group : 'org.junit.vintage' , module: 'junit-vintage-engine' } testImplementation 'junit:junit' 切記要 test packageage 和 main package 一致