我的周日挑战是将特定年份的工作日获取并保存到 CSV 等文件中。
我有以下代码,我面临的问题是:如何以特定格式(即 YYYYMMDD)打印日期,因为代码当前打印的内容类似于 2019 年 1 月 19 日星期六 00:00:00 CET。
另外,如果我可以排除周末,并且通常是否有更好的方法在 Java 8 中编写更短的代码。
import java.io.*;
import java.util.*;
import java.text.SimpleDateFormat;
public class DatesInYear
{
public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
public static void main (String[] args) throws java.lang.Exception
{
Date dt = new Date();
System.out.println(dt);
List<Date> dates = printDates("20190101","20191231");
Collections.reverse(dates);
System.out.println(dates.size());
for(Date date:dates)
{
SimpleDateFormat format1 = new SimpleDateFormat("yyyyMMdd");
System.out.println(format1.format(date));
}
}
public static List<Date> printDates(String fromDate, String toDate)
{
ArrayList<Date> dates = new ArrayList<Date>();
try …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 WireMock 创建动态模拟。我有一种情况,如果我指定 URL 如下:
http://localhost:8089/api/account/abc@abc.com
Run Code Online (Sandbox Code Playgroud)
那么我应该收到如下回复:
{
"account" : "abc@abc.com"
}
Run Code Online (Sandbox Code Playgroud)
简而言之,路径参数在响应正文中返回。我可以使用urlPathPatternset to 使请求 URL 通用,/api/account/([a-z]*)但是我不确定我应该如何abc@abc.com使用正则表达式在响应中捕获和返回它。
尝试使用 Cucumber 执行 Spring Boot 项目时,我遇到以下错误。快速搜索错误告诉我,我的 pom 文件中需要 spring-tx 。我有一个问题不应该由 spring-boot-configuration-processor 等来处理吗?
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/transaction/TransactionDefinition
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetPublicMethods(Class.java:2902)
at java.lang.Class.getMethods(Class.java:1615)
at cucumber.runtime.java.MethodScanner.scan(MethodScanner.java:40)
at cucumber.runtime.java.JavaBackend.loadGlue(JavaBackend.java:86)
at cucumber.runtime.Runtime.<init>(Runtime.java:92)
at cucumber.runtime.Runtime.<init>(Runtime.java:70)
at cucumber.runtime.Runtime.<init>(Runtime.java:66)
at cucumber.api.cli.Main.run(Main.java:35)
at cucumber.api.cli.Main.main(Main.java:18)
Caused by: java.lang.ClassNotFoundException: org.springframework.transaction.TransactionDefinition
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 11 more
Run Code Online (Sandbox Code Playgroud)
我基本上试图评估 Spring Boot 是否是 Cucumber + Selenium + API 等的更好选择,而不是使用以下项目https://github.com/sorin-costea/bdd的 vanilla spring