小编Voj*_*ěch的帖子

在TypeScript中声明抽象方法

我试图弄清楚如何在TypeScript中正确定义抽象方法:

使用原始继承示例:

class Animal {
    constructor(public name) { }
    makeSound(input : string) : string;
    move(meters) {
        alert(this.name + " moved " + meters + "m.");
    }
}

class Snake extends Animal {
    constructor(name) { super(name); }
    makeSound(input : string) : string {
        return "sssss"+input;
    }
    move() {
        alert("Slithering...");
        super.move(5);
    }
}
Run Code Online (Sandbox Code Playgroud)

我想知道如何正确定义方法makeSound,因此它是键入的并且可能被覆盖.

此外,我不知道如何正确定义protected方法 - 它似乎是一个关键字,但没有效果,代码将无法编译.

typescript

171
推荐指数
2
解决办法
11万
查看次数

仅标记为回滚的事务:如何查找原因

我在@Transactional方法中提交事务时遇到问题:

methodA() {
    methodB()
}

@Transactional
methodB() {
    ...
    em.persist();
    ...
    em.flush();
    log("OK");
}
Run Code Online (Sandbox Code Playgroud)

当我从methodA()调用methodB()时,该方法成功通过,我可以在日志中看到"OK".但后来我明白了

Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:521)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
    at methodA()...
Run Code Online (Sandbox Code Playgroud)
  1. 方法B的上下文在异常中完全丢失 - 我想这没关系?
  2. methodB()中的某些内容将事务标记为仅回滚?我怎么能找到它?例如,有一种方法来检查类似的东西getCurrentTransaction().isRollbackOnly()?- 像这样我可以逐步完成方法并找到原因.

java spring hibernate jpa transactions

83
推荐指数
7
解决办法
21万
查看次数

在Kotlin中使用接口的默认功能实现

我有一个带有默认实现的Kotlin接口,例如:

interface Foo {
    fun bar(): String {
        return "baz"
    }
}
Run Code Online (Sandbox Code Playgroud)

在我尝试从Java实现此接口之前,这是可以的.当我这样做时,它表示该类需要被标记为抽象或实现该方法bar().此外,当我尝试实现该方法时,我无法调用super.bar().

kotlin

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

@JoinFormula和@OneToMany定义 - 糟糕的文档

我有两个关于@JoinFormula和@OneToMany注释的问题:

  1. 如何用注释@JoinFormula@OneToMany注释限制结果的数量?

  2. 我如何定义id表达式author = id中指的是Author.id

    Author {
    
        @Id
        private Long id;
    
        @OneToMany
        @JoinFormula(value = "SELECT a FROM Article a WHERE author = id AND schedule < CURRENT_TIMESTAMP()") // limit = 15
        private List<Article> pastArticles;
    }
    
    Run Code Online (Sandbox Code Playgroud)

像这样,即使我删除schedule <了条款的一部分,我仍然将pastArticles保持为空.

谢谢!

java persistence hibernate

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

在呈现之前隐藏vue.js模板

我想在完全呈现之前隐藏vue.js模板的内容.考虑以下模板:

<div class="loader"> 
  <table class="hidden">
    <tr v-for="log in logs">
      <td>{{log.timestamp}}</td>
      <td>{{log.event}}</td>
    </tr>
  </table>
</div>
Run Code Online (Sandbox Code Playgroud)

当我在服务器上呈现此模板时,用户<tr>在呈现之前会看到该元素的内容.出于这个原因,我hidden在完全呈现之前使用该类来隐藏它.

在渲染之前,我正在显示一个带有一些动画进度条的loader元素.

渲染完成后,我只需调用element.show()jQuery并隐藏进度条.我的问题是:混合jQuery和vue.js可以实现这个吗?

var vueLogs = new Vue({
  el: "#checkInLogsHolder",
  data: {logs: []}
});
var holder = $("#checkInLogsHolder");

function response(payload) {
  // hiding the loader animation
  holder.find(".loader").remove();
  // showing the rendered table
  holder.find("table").show();
  vueLogs.logs.unshift(payload);
}
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来做到这一点?

vue.js

23
推荐指数
2
解决办法
2万
查看次数

在Java中使用Kotlin类:找不到符号

我发现这个关于Android的类似的问题,但我使用普通的Java与Maven作为构建工具.我认为最好发一个新问题.

我创建了一个Kotlin类,我试图从Java类中引用它MyKotlinClass.class.Maven构建失败,而IntelliJ Idea中的编译工作正常.我已经为maven添加了Kotlin插件:

        <plugin>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-plugin</artifactId>
            <version>${kotlin.version}</version>
            <executions>
                <execution>
                    <id>compile</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>test-compile</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

但是这没有帮助:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project app: Compilation failure
[ERROR] MyClassLinkingKotlin.java:[100,40] error: cannot find symbol
Run Code Online (Sandbox Code Playgroud)

线/列恰好指代符号MyKotlinClass.class.即使使用这样的话它也会失败:

System.err.println(MyKotlinClass.class)
Run Code Online (Sandbox Code Playgroud)

java interop build maven kotlin

17
推荐指数
4
解决办法
8685
查看次数

将GIT存储库更改为共享

Git允许在一个组中创建一个共享存储库:

git --bare init --shared=group
Run Code Online (Sandbox Code Playgroud)

但是 - 如何将现有存储库更改为共享?我不想重新git-init它.

git bash

15
推荐指数
2
解决办法
2万
查看次数

在Kotlin正确实施等待和通知

根据这个文件,在Kotlin中使用waitnotify不鼓励:https://kotlinlang.org/docs/reference/java-interop.html

等待()/通知()

有效的Java Item 69建议更喜欢并发实用程序来wait()和notify().因此,这些方法不适用于Any类型的引用.

但是,该文件没有提出任何正确的方法.

基本上,我想实现一个服务,它将读取输入数据并处理它们.如果没有输入数据,它将暂停,直到有人通知有新的输入数据.就像是

while (true) {
    val data = fetchData()
    processData(data)
    if (data.isEmpty()) {
        wait()
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:

我不想使用这些不推荐的方法(反模式),我真的想知道如何正确地做到这一点.

在我的情况下fetchData从数据库中读取数据,因此在我的情况下不能使用队列.

kotlin

15
推荐指数
2
解决办法
8749
查看次数

移动浏览器中的Zoomable/Scrollable HTML"窗口"

我正在尝试创建一个<div>内部元素的窗口,以便能够在移动设备上滚动/缩放其内容,如下所示:

http://jsfiddle.net/hk1jfp4z/

我希望能够做到以下几点:

  1. 页面加载:缩放#scrollable_zoomable_background以适合#window.
  2. 为了能够用两个手指手势进行缩放,请使用touchstart,touchend进行滚动
  3. 页面的其余部分不能缩放,也不能水平滚动(带<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"/>)
  4. #window一定不可以出现在iframe,它需要的文档结构的一部分.

html javascript css responsive-design

14
推荐指数
2
解决办法
393
查看次数

Maven Shade Plugin生产两个罐子

直到现在我使用maven程序集插件为每个工件生成两个JAR - 编译源和依赖项 - 原因很简单 - 仅通过网络部署已编译的源比使用40 MB部署一体式JAR要快得多数据的.

由于覆盖了内部文件,我不得不切换maven shade插件才能使用该<transformers>功能.但是我无法管理两个执行:

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
      <execution>
        <id>shade-libs</id>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <outputFile>target/assembly/${project.artifactId}-libs.jar</outputFile>
          <artifactSet>
            <excludes>
              <exclude>...</exclude>
            </excludes>
          </artifactSet>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
              <resource>META-INF/spring.handlers</resource>
            </transformer>
            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
              <resource>META-INF/spring.schemas</resource>
            </transformer>
          </transformers>
        </configuration>
      </execution>
    </executions>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
      <execution>
        <id>shade-main</id>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <outputFile>target/assembly/${project.artifactId}.jar</outputFile>
          <artifactSet>
            <includes>
              <include>...</include>
            </includes>
          </artifactSet>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)

当我运行时mvn package,只运行第二次执行.第一个总是被忽略.使用maven程序集插件,它运行得很好.

当然解决方案可能是同时使用装配和阴影插件,但我想找到更一致的解决方案.

maven maven-assembly-plugin maven-shade-plugin

13
推荐指数
1
解决办法
9059
查看次数