小编Ann*_*ein的帖子

无限IntStream的长度?

我已经创建了一个randomIntStream:

 final static PrimitiveIterator.OfInt startValue = new Random().ints(0, 60).iterator();
Run Code Online (Sandbox Code Playgroud)

文档说这个流实际上是无穷无尽的.

我想了解背景中发生了什么.

ints(0,60)正在生成无限的整数流.如果这是无限的,为什么我的机器没有泄漏任何内存?

我想知道,实际上生成了多少个数字,以及这个实现是否会在流仍然结束时导致错误?或者这个流会不断地在飞行中充满新的整数,它真的永远不会结束吗?

如果我已经提出这个问题,那么现在生成随机数的最佳做法是什么?

java random java-stream

16
推荐指数
3
解决办法
1552
查看次数

HTML元素的值未定义但已设置

我想在页面渲染到后端的匹配状态后设置复选框.

为此目的,我实现了这个功能到目前为止的工作是什么

更新为user-suggestion cbs [i] .dataset.thvalue或cbs [i] .dataset.value无关紧要

 function updateCheckboxes () {

  let activeCheckbox = '<input type="checkbox" onclick="handleClickOnReduce()" checked>'
  let inactiveCheckbox = '<input type="checkbox" onclick="handleClickOnReduce()">'

  let cbs = document.getElementsByTagName('td')
  for (let i = 0; i < cbs.length; i++) {
    if (cbs[i].id === 'reduceCheckbox' || cbs[i].id === 'slCheckbox') {
      if (cbs[i].dataset.thvalue === 'true') {
        cbs[i].innerHTML = activeCheckbox
      }
      else {
        cbs[i].innerHTML = inactiveCheckbox
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

HTML部分,使用Thymeleaf

    <td id="reduceCheckbox" data-th-value="${car.isReduced()}"></td>
    <td id="slCheckbox" data-th-value="${car.isSl()}"></td>
Run Code Online (Sandbox Code Playgroud)

但浏览器通过打印输出值来声明它是未定义的,即使设置的值正如您在浏览器中的实时图片中所看到的那样.

在此输入图像描述

由于文档我的语法应该是正确的?

https://www.w3schools.com/jsref/prop_option_value.asp

有什么建议吗?

javascript thymeleaf

10
推荐指数
2
解决办法
658
查看次数

没有通过 Sequelize 实例

我试图dbInit从我的 dbController外包我的函数模型,因为我有几个模型使 dbController 变大。

所以我initDb从我的db_controller.js看起来像这样打电话(我使用那个文档http://docs.sequelizejs.com/manual/getting-started.html

const userModel = require('../model/user')
const subjectModel = require('../model/subject')
const Sequelize = require('sequelize')
const seq = new Sequelize({
  dialect: 'sqlite',
  storage: './user.db'
})

async function initDb () {
  await userModel.user.initUser()
  await subjectModel.subject.initSubject()
  userModel.user.userClass.hasMany(subjectModel.subject.subjectClass)
}
Run Code Online (Sandbox Code Playgroud)

用户user.js看起来像这样:

const Sequelize = require('sequelize')
const seq = new Sequelize({
  dialect: 'sqlite',
  storage: './user.db'
})

class User extends Sequelize.Model {
}

exports.user = {
  initUser: initUser,
  userClass: User
}

async …
Run Code Online (Sandbox Code Playgroud)

node.js sequelize.js

8
推荐指数
1
解决办法
9548
查看次数

我是否必须在流读取的列表上进行同步?

如果我有一个线程敏感列表,我通常会这样迭代它:

    List list = Collections.synchronizedList(new ArrayList());
...
synchronized(list) {
    Iterator i = list.iterator(); // Must be in synchronized block
    while (i.hasNext())
        foo(i.next());   
}
Run Code Online (Sandbox Code Playgroud)

我想知道我是否使用list.stream()然后在流上执行某些操作,如过滤器等,如果我还必须将列表放入同步块中,或者流是否制作了列表的副本?

谢谢

java java-8 java-stream

7
推荐指数
1
解决办法
990
查看次数

承诺问题:ReferenceError:拒绝未定义

我正在使用一些自己构建的承诺示例来了解此功能的工作原理。

以下代码产生错误

参考错误:拒绝未定义

我从节点 Promise.js 开始,并使用节点版本 8.11.3

这是我的代码,产生错误的部分用“问题

function testPromise () {

//part 1
  function checkCountOnServer () {
    return new Promise(function (resolve, reject) {
      var available = false
      if (available) {
        resolve('available')
      }
      else {
        reject('not available')
      }
    })
  }

  function checkPayment () {
    return new Promise(function (resolve, reject) {
      var booleanTest = true
      if (booleanTest) {
        resolve('payment done')
      }
      else {
        reject('no payment received')
      }
    })
  }

  var checkCountOnServerVar = checkCountOnServer()
  checkCountOnServerVar.then(function (resolve) {
    console.log(resolve)
    return resolve(checkPayment())
  }, function …
Run Code Online (Sandbox Code Playgroud)

javascript

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

无法解析类或包H2

我为我的Spring应用程序使用H2数据库.问题是,一切正常.我可以访问,存储和重新连接到数据库.但是,我收到了IDE的警告

无法解析类或包H2

在这

spring.datasource.driver-class-name=org.h2.Driver
Run Code Online (Sandbox Code Playgroud)

这有点让人困惑,因为我不知道是否以及如何处理这个问题.这曾经是一个类似的问题,但答案没有帮助,我不知道我是否可以再次提出这个问题,或者我是否应该在现有的帖子中发布我的问题?

这是我的application.properties

spring.datasource.url=jdbc:h2:file:~/afile;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE
spring.datasource.username=no:)
spring.datasource.password=no:)
spring.datasource.driver-class-name=org.h2.Driver
#spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
Run Code Online (Sandbox Code Playgroud)

我的POM

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>10</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.6</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-websocket</artifactId>
        <version>2.0.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.4.197</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>jquery</artifactId> …
Run Code Online (Sandbox Code Playgroud)

h2 spring-jdbc maven spring-data-jpa spring-boot

2
推荐指数
1
解决办法
1564
查看次数

使用java 8从过去获取Unix时间戳

从Java 8开始我可以使用instantLocalDateTime

要获取Unix时间戳:

long unixTimestamp = Instant.now().getEpochSecond();
Run Code Online (Sandbox Code Playgroud)

但是,如果我想从过去得到一个时间,让我说2周我用这个:

int unixtime2weeksAgo = (int) ((System.currentTimeMillis() - 24 * 60 * 60 * 1000 * 14) / 1000L)
Run Code Online (Sandbox Code Playgroud)

有了这些文档,我无法构建基于新的Java 8功能的解决方案,有人可以通过使用Instant或LocalDateTime提供一个好的解决方案吗?

java

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

角度材质按钮与主题不匹配

我刚刚安装了 Angular 10 和 Angular Materialsng add @angular/material

我在那里选择自定义主题:紫色/绿色

下一步是简单地添加一个工具栏,基本上是从谷歌网站复制粘贴。但我无法排列与主题相匹配的按钮。我不知道为什么它看起来像这样。

在此输入图像描述

它应该是什么样子

在此输入图像描述

<mat-toolbar color="primary">
  <button mat-icon-button aria-label="Example icon-button with menu icon">
    <mat-icon>menu</mat-icon>
  </button>
  <span>My App</span>
  <span class="nav-spacer"></span>
  <button mat-icon-button class="material-icons-outlined" aria-label="Example icon-button with heart icon">
    <mat-icon>favorite</mat-icon>
  </button>
  <button mat-icon-button class="example-icon" aria-label="Example icon-button with share icon">
    <mat-icon>share</mat-icon>
  </button>
</mat-toolbar>
Run Code Online (Sandbox Code Playgroud)

我的 stlye.css

/* You can add global styles to this file, and also import other style files */

html, body { height: 100%; }
body { margin: 0; font-family: Roboto, "Helvetica …
Run Code Online (Sandbox Code Playgroud)

css angular-material angular

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

Hibernate:创建表异常

我突然有一个hibernate异常,无法找到问题.到目前为止,我的应用程序实际上工作得很好但是某些/某种方式/某些我必须更改导致错误的内容.但我没有找到它.

这里的错误:

2018-08-26 15:07:41.273  INFO 4580 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate Core {5.3.2.Final}
2018-08-26 15:07:41.274  INFO 4580 --- [  restartedMain] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2018-08-26 15:07:41.330  INFO 4580 --- [  restartedMain] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2018-08-26 15:07:41.418  INFO 4580 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2018-08-26 15:07:41.845  INFO 4580 --- [  restartedMain] org.hibernate.tuple.PojoInstantiator     : HHH000182: No default (no-argument) constructor for class: com.trademerger.trading.observable.TradeDistributingUnitExchange (class must be instantiated by Interceptor)
Hibernate: drop …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate jdbc h2

0
推荐指数
1
解决办法
1710
查看次数