小编Les*_*iak的帖子

如何在Dart中向TableElement添加行?

我正在玩Dart,我正在尝试创建一个带有标题和tbody中的一行的新TableElement.

  TableElement table = new TableElement();

  Element head = table.createTHead();
  TableRowElement headerRow =  table.tHead.insertRow(-1);
  headerRow.insertCell(0).text = "9";
  headerRow.insertCell(1).text = "aaa";
  headerRow.insertCell(2).text = "bbb";
  headerRow.insertCell(3).text = "ccc";

  var tBody = table.createTBody();
  TableRowElement newLine = table.insertRow(-1); // add at the end
  newLine.insertCell(0).text = "9";
  newLine.insertCell(1).text = "aaa";
  newLine.insertCell(2).text = "bbb";
  newLine.insertCell(3).text = "ccc";
Run Code Online (Sandbox Code Playgroud)

不幸的是,这两行最终都出现在thead部分.最重要的是,如果我只离开

  TableElement table = new TableElement();

  var tBody = table.createTBody();
  TableRowElement newLine = table.insertRow(-1); // add at the end
  newLine.insertCell(0).text = "9";
  newLine.insertCell(1).text = "aaa";
  newLine.insertCell(2).text = "bbb";
  newLine.insertCell(3).text …
Run Code Online (Sandbox Code Playgroud)

html dart

6
推荐指数
1
解决办法
2208
查看次数

使用 Clock.fixed() 模拟 LocalDate.now(clock)

当我设置特定日期时,我正在努力测试我的端点。

我不想使用 PowerMock 来模拟静态方法,而是决定更改服务的实现并使用 LocalDate.now(Clock Clock) 实现,以便更容易测试它。

我添加到我的 SpringBootApplication 类中:

@Bean
public Clock clock() {
    return Clock.systemDefaultZone();
}
Run Code Online (Sandbox Code Playgroud)

并将其自动连接到我的服务

@Autowired
private Clock clock;
Run Code Online (Sandbox Code Playgroud)

并在我的实现中使用它:

LocalDateTime localDate = LocalDateTime.now(clock);
Run Code Online (Sandbox Code Playgroud)

在测试方面我嘲笑了时钟

private final static LocalDate WEEKEND = LocalDate.of(2020, 07, 05);

@Mock
private Clock clock;
private Clock fixedClock;
Run Code Online (Sandbox Code Playgroud)

并这样使用它:

MockitoAnnotations.initMocks(this);

//tell your tests to return the specified LOCAL_DATE when calling LocalDate.now(clock)
fixedClock = Clock.fixed(WEEKEND.atTime(9, 5).toInstant(ZoneOffset.UTC), ZoneId.of("CET"));
doReturn(fixedClock.instant()).when(clock).instant();
doReturn(fixedClock.getZone()).when(clock).getZone();

ResponseEntity<String> response = restTemplate.postForEntity(base.toString(), request, String.class);
Run Code Online (Sandbox Code Playgroud)

当我调试它时,它fixedClock具有我期望的值FixedClock[2020-07-05T09:05:00Z,CET]。相反,如果我在服务实现上放置断点,则该localDate变量的值是2020-07-09- …

java testing junit mockito spring-boot

6
推荐指数
1
解决办法
8332
查看次数

具有可变组数的正则表达式中的Emoji Unicode

我知道这是一个极端的情况,但是我遇到了一个使用正则表达式且组数可变的代码

根据文档,这是合法的:

与组关联的捕获输入始终是该组最近匹配的子序列。如果由于量化而对组进行第二次评估,则如果第二次评估失败,则先前保留的值(如果有)将保留。例如,将字符串“ aba”与表达式(a(b)?)+匹配,则将第二组设置为“ b”。在每次比赛开始时,所有捕获的输入都会被丢弃。

但是,当我尝试将其与unicode符号“带有笑脸的咧嘴笑脸”(U + 1F601)一起使用时,出现StringIndexOutOfBoundsException。

根据规范或错误是预期的吗?

这是测试代码:

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TestEmoji {
    public static void main(String[] args)  {
        Pattern pattern = Pattern.compile("(A.)* EEE");

        testGroups(pattern, "ACAB EEE");
        testGroups(pattern,  "ABACA\uD83D\uDE01");

    }

    public static void testGroups(Pattern pattern, String s) {
        Matcher matcher = pattern.matcher(s);
        if (matcher.matches()) {
            System.out.println("matches");
            System.out.println(matcher.groupCount());
            for (int i = 1; i <= matcher.groupCount(); ++i) {
                System.out.println(matcher.group(i));
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

和例外:

matches
1
AB
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index …
Run Code Online (Sandbox Code Playgroud)

java regex unicode

5
推荐指数
1
解决办法
1157
查看次数

如何使用 SnakeYaml 加载自定义对象列表

我一直在尝试List<Stage>使用 SnakeYaml将以下 yaml 反序列化:

- name: Stage1
  items: 
    - item1
    - item2

- name: Stage2
  items: 
    - item3

Run Code Online (Sandbox Code Playgroud)
public class Stage {
    private String name;
    private List<String> items;

    public Stage() {
    }

    public Stage(String name, List<String> items) {
        this.name = name;
        this.items = items;
    }

    // getters and setters
}
Run Code Online (Sandbox Code Playgroud)

我发现的最接近的问题是SnakeYaml Deserialise Class contains a List of Objects。阅读后,我知道ConstructorTypeDescriptor类,但我仍然无法让它工作(我得到的是 HashMaps 列表,而不是 Stages)。

与上面链接中的问题不同的是,我的顶级结构是一个列表,而不是一个自定义对象。

java snakeyaml

5
推荐指数
1
解决办法
1218
查看次数

JOOQ 如何在不展平属性的情况下获取连接到 POJO 的结果?

我有以下查询,我连接表AB以及C

  • CB通过有关C.B_ID
  • BA通过有关B.A_ID

我想检索一份报告,其中对于每个C,我还想从相应的B和 中检索字段A。如果只需要字段的子集,则投影和提取到 POJO(具有来自C, B, 的必需属性A)是一种显而易见的方法。

class CReportDTO {
    Long c_id;
    Long c_field1;
    Long c_bid;
    Long b_field1;
    // ...
    CReportDTO(Long c_id, Long c_field1, Long c_bid, Long b_field1) {
        // ...
    }

    // ..
}
Run Code Online (Sandbox Code Playgroud)
public List<CReportDTO> getPendingScheduledDeployments() {
        return dslContext.select(
                C.ID,
                C.FIELD1,
                C.B_ID,
                B.FIELD1,
                B.A_ID
                A.FIELD1,
                A.FIELD2
                )
                .from(C)
                .join(B)
                .on(C.B_ID.eq(B.ID))
                .join(A)
                .on(B.A_ID.eq(A.ID)) …
Run Code Online (Sandbox Code Playgroud)

java sql jooq

5
推荐指数
1
解决办法
563
查看次数

Typescript: Instance of class type

I have the type of a class like here as A_Type?

class A {
  constructor(public a: string) {}
}

type A_Type = {new (a: string): A}
Run Code Online (Sandbox Code Playgroud)

And Id like to get the type of the instance of the A_Type constructor, so that I could type this function explicitly

class A {
  constructor(public a: number) {}
}
//                                              ** not working **
function f<W extends { new(a: number): A }>(e: W): instanceof W {
  return new e(2)
}

let w …
Run Code Online (Sandbox Code Playgroud)

typescript

5
推荐指数
1
解决办法
1万
查看次数

hsqldb 和 jdk8 兼容性

我尝试在我的 Maven 项目中使用 org.hsqldb.hsqldb 。客户端的要求是使用Java 8。org.hsqldb.hsqldb当前版本是2.6.1,似乎不能与Java 8一起使用。如何观察使用Java 8编译的HSQLDB版本?

java version hsqldb maven

4
推荐指数
1
解决办法
2064
查看次数

cy.origin() 和立即重定向

我在测试受 oauth 保护的应用程序时遇到问题。当没有公共页面时,问题就会显现出来 - 如果用户未经过身份验证,就会立即重定向到 OAuth 服务器。

我设法以更简单的设置重现该问题:

  • 在 fake-app 域中运行的假应用程序
  • 在 fake-oauth-server 域中运行的假 oauth 服务器

以下是各自的应​​用程序(在 Flask 中):

假应用程序

from flask import Flask, redirect, render_template_string

app = Flask(__name__)

app_host="fake-app"
app_port=5000
app_uri=f"http://{app_host}:{app_port}"
oauth_host="fake-oauth-server"
oauth_port=5001
oauth_uri=f"http://{oauth_host}:{oauth_port}"

@app.route('/')
def hello():
    return render_template_string('''<!doctype html>
           <html>
               <body>
                   <p>Hello, World MainApp!</p>
                   <a id="loginButton" href="{{ oauth_uri }}?redirect_uri={{ app_uri }}">Login</a>
               </body>
           </html>
           ''',
           oauth_uri=oauth_uri,
           app_uri=app_uri
    )

@app.route('/goto-oauth')
def goto_oauth():
    return redirect(f"{oauth_uri}?redirect_uri={app_uri}")

if __name__ == '__main__':
    app.run(host=app_host, port=app_port)
Run Code Online (Sandbox Code Playgroud)

假oauth服务器:

from flask import Flask, render_template_string, request

app = Flask(__name__) …
Run Code Online (Sandbox Code Playgroud)

cypress cypress-origin

4
推荐指数
1
解决办法
3586
查看次数

飞镖图库布局

我正在努力使用Dart库布局.我尝试了以下内容

lib/
  A.dart
  B.dart
  my_lib.dart
Run Code Online (Sandbox Code Playgroud)

其中:A.dart

class A {
  B myB;   
}
Run Code Online (Sandbox Code Playgroud)

B.dart

class A {
  B myB;   
}
Run Code Online (Sandbox Code Playgroud)

my_lib.dart

#library('my_lib');
#source('A.dart');
#source('B.dart');  
Run Code Online (Sandbox Code Playgroud)

但是在A.dart中,在Dart编辑器中存在一个问题:B - 没有这种类型.如果我在该文件中导入B.dart,则通过

#import('B.dart)',
Run Code Online (Sandbox Code Playgroud)

但现在它声称库的一部分只能包含部分指令.根据http://news.dartlang.org/2012/07/draft-spec-changes-to-library-and.html

partDirective:
  metadata part  stringLiteral “;”
;
Run Code Online (Sandbox Code Playgroud)

但这对我也不起作用.我错过了什么?

dart

3
推荐指数
1
解决办法
1405
查看次数