小编Jes*_*per的帖子

系统输出println

我在控制台上打印了2行.它们都打印,但是当第二个打印时,第一个打印到第二个,所以2行是相同的.我以前从未遇到过这个.为什么第二次打印会覆盖第一次打印,我该如何解决?

public static void main(String args[]){
    new MergeSort(90000);

    System.out.println("Array to be mergesorted: " +Arrays.toString(array));

    long start = System.currentTimeMillis();

    mergeSort(array, 1, array.length);

    long end = System.currentTimeMillis();

    System.out.println("Result: " + Arrays.toString(array) );
}
Run Code Online (Sandbox Code Playgroud)

构造函数:

public MergeSort(int n){
    Random rand = new Random();
    array = new int[n];
    for(int i = 0; i <array.length; i++){
        array[i] = rand.nextInt(101);
    }
}
Run Code Online (Sandbox Code Playgroud)

其余代码:

public static void merge(int[] A, int p, int q, int r){
    //
    //length of subarray 1
    int n1 = q-p+1;

    //length of subarray …
Run Code Online (Sandbox Code Playgroud)

java

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

表单控件未定义

我的表格是通过以下方式制作的:

<form #form="ngForm" novalidate (ngSubmit)="register(form);">
    <div class="registerinput">
        <label for="firstname">First Name</label>
        <input #firstname="ngModel" type="text" name="firstname" maxlength="30" pattern="[a-zA-Z ]*" required ngModel>
        <div [hidden]="!form.controls.firstname.touched && !form.controls.firstname.errors?.required" class="alert-danger">
            Please enter your name
        </div>
        <div [hidden]="!form.controls.firstname.touched && !form.controls.firstname.errors?.maxlength" class="alert-danger">
             Max length is 30 characters
        </div>
        <div [hidden]="!form.controls.firstname.touched && !form.controls.firstname.errors?.pattern" class="alert-danger">
             Only letters are allowed
        </div>
    </div>
    <div class="registerinput">
        <button type="submit" class="btn-register">Register</button>
    </div>
</form>
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

EXCEPTION: Uncaught (in promise): Error: Error in http://localhost:3000/app/register/register.component.html:7:17 caused by: Cannot read property 'touched' of undefined
Error: Error in http://localhost:3000/app/register/register.component.html:7:17 caused …
Run Code Online (Sandbox Code Playgroud)

forms angular

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

如何禁用量角器中的动画?

我在Google上找到了一些答案,但它们似乎不适用于我的项目。

一些答案是关于在conf.js文件onPrepare()功能中添加一些代码的,但是我的项目中没有该文件。我有一个名为的文件protractor.config.js,默认情况下该文件位于angular快速入门项目中。无论如何,此配置文件也具有一个onPrepare()功能,因此我尝试从以下问题的答案#2中添加代码:如何在角度js应用程序的量角器中禁用动画,但是随后我的测试失败了:

message: Failed: Trying to load mock modules on an Angular2 app is not yet supported.
Run Code Online (Sandbox Code Playgroud)

protractor angular

4
推荐指数
2
解决办法
3054
查看次数

ArrayList在每个索引处返回0

所以我在这个练习中遇到了一些麻烦.我通过在每个线程中同步arraylist来解决其中一个问题,但仍然有问题.arraylist"data"用0到9999之间的数字填充.但是,data.get(i); 似乎每个指数都会返回0,我不能为我的生活找出原因.这是代码:

private static int LIST_TRAVERSE_LIMIT = 10000; // size of problem

private boolean problem_3_failed = false; // set to true if failed

private List<Integer> data = new ArrayList<Integer>(); // data shared between threads, traversed and modified

private int negative_hits = 0; // counter for how many modifications are found during traversal

private void test_parallel_iteration() {
    for(int i=0; i<LIST_TRAVERSE_LIMIT; i++) data.add(i);
    // Define threads and run them
    Thread t1 = new Thread(() -> { // modify the list in just …
Run Code Online (Sandbox Code Playgroud)

java arraylist

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

如何使用 highcharts 和 angular 启用 noData

我想启用“noData”功能,默认情况下,当图表中没有要显示的数据时,它会显示一条消息。它在他们的文档中说该功能需要将文件no-data-to-display.js加载到页面中。

我的 node_modules/highcharts 文件夹中已经有了这个文件,但我不确定我应该如何从那里加载它,所以我也想知道如何做到这一点。现在,我通过将这个脚本标签添加到我的index.html

<script src="http://code.highcharts.com/modules/no-data-to-display.js"></script> 
Run Code Online (Sandbox Code Playgroud)

它给了我以下错误:

Uncaught ReferenceError: Highcharts is not defined
    at no-data-to-display.js:10
    at no-data-to-display.js:10
Run Code Online (Sandbox Code Playgroud)

这是我的所有 highcharts 相关内容 app.module.ts

import { ChartModule } from 'angular2-highcharts';
import { HighchartsStatic } from 'angular2-highcharts/dist/HighchartsService';
import * as Highcharts from 'highcharts';

imports: [
    ChartModule,
],
providers: [{
    provide: HighchartsStatic,
    useValue: Highcharts
}]
Run Code Online (Sandbox Code Playgroud)

谢谢。

编辑:

我试图在我的app.module.ts

import HighchartsNoDataToDisplay from 'highcharts/modules/no-data-to-display.src.js';
Run Code Online (Sandbox Code Playgroud)

我不确定下一步是什么。将 HighchartsNoDataToDisplay 添加到导入数组会给我一个错误。

highcharts angular2-highcharts angular

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

Array slice()提供引用而不是值

我有一个文件,我正在导出这样的对象:

export const LINECHART2_DATA = {
    series: [{
        data: [],
        name: 'HR',
    },
    { 
        etc...
    }]
}
Run Code Online (Sandbox Code Playgroud)

我这样导入它:

import { LINECHART2_DATA } from '../chart-options/options';
Run Code Online (Sandbox Code Playgroud)

我有以下方法:

prepareLineChartDataContainer(bed: BedDetails) {
//Clear data to prepare for new bed
if (bed.seriesContainer == null) {
  bed.seriesContainer = LINECHART2_DATA.series.slice();
} else {
  bed.seriesContainer.forEach(series => {
    series.data.length = 0;
  });
}
//Add data to seriesContainer
this.vitalSigns.forEach(vs => {
  bed.timeWindows.forEach(tw => {
    bed.seriesContainer.find(series => series.name == vs).data.push(tw['avg' + vs]);
  });
});
}
Run Code Online (Sandbox Code Playgroud)

正如您在上面所看到的,我正在切割系列数组LINECHART2_DATA,然后将一些数据推送到它.当bed使用null seriesContainer …

javascript typescript angular

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

多租户休眠不会在租户之间切换

我正在将 spring + hibernate + mysql 设置更改为多租户。首先,我的 中有以下内容application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/test?useSSL=false
spring.datasource.username=root
spring.datasource.password=root
Run Code Online (Sandbox Code Playgroud)

我不确定test引入多租户后是否应该让它连接到此处的特定模式 ( )?这对我来说没有意义,因为如果没有提供租户,它应该使用默认架构,否则连接到与租户关联的架构。但是,如果我删除它,我会收到一条错误消息,指出未提供数据库。

其次,多租户部分似乎不起作用。我所有的查询都是在test架构中进行的。我已经实施了以下措施MultiTenantConnectionProvider

@Component
public class TenantConnectionProvider implements MultiTenantConnectionProvider {
private Datasource datasource;

public TenantConnectionProvider(DataSource datasource) {
    this.datasource = datasource;
}

...

@Override
public Connection getConnection(String tenantIdentifier) throws SQLException {
    logger.info("Get connection for tenant {}", tenantIdentifier);
    final Connection connection = getAnyConnection();
    connection.setSchema(tenantIdentifier);
    return connection;
}

@Override
public void releaseConnection(String tenantIdentifier, Connection connection) throws SQLException {
    logger.info("Release connection for tenant {}", …
Run Code Online (Sandbox Code Playgroud)

java mysql spring hibernate multi-tenant

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

查询不返回数据库

我正在尝试使用该值从我的数据库中获取汽车FK_adId.我尝试使用FK_adId值52 调用方法,并且检查了FK_adId数据库中存在值为52 的汽车.为什么不归还给我?

public Car getCar(int adId) {
    Car car = null;
    try {
        Class.forName("org.postgresql.Driver");
        if (con != null) {
            ps = con.prepareStatement("SELECT * FROM \"car\" WHERE \"FK_adId\" = ?;");
            ps.setInt(1, adId);
            rs = ps.executeQuery();
            rs.next();
            if (rs.next()) {
                car = new Car(rs.getString("brand"), rs.getString("vin"), rs.getString("condition"), rs.getInt("distanceTraveled"), rs.getInt("age"), rs.getInt("price"), rs.getInt("FK_adId"));
            }
        }
    } catch (Exception ex) {
        System.out.println(ex);
    }
    return car;
}
Run Code Online (Sandbox Code Playgroud)

java postgresql

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

带有括号属性访问器的安全导航操作符

我遇到过无法使用点表示法访问属性的情况,因为属性的名称包含点。

我有一个名为 的对象translations,其属性包含字符串翻译,例如该Tooltip.O2属性包含图像工具提示的翻译:

<img [matTooltip]="translations?.Tooltip.O2" [src]="bed.additionalO2 ? medO2 : noO2">
Run Code Online (Sandbox Code Playgroud)

当我这样做时,它认为我正在尝试访问带有属性的Tooltip内部对象。我知道我可以使用括号表示法来访问它:translationsO2

[matTooltip]="translations['Tooltip.O2']"
Run Code Online (Sandbox Code Playgroud)

但是,安全导航运算符似乎不能?与括号表示法一起使用。我试图写translations?['Tooltip.O2'],但它导致了错误。

我想知道是否有一种方法可以使用点表示法访问该属性,或者是否有一种方法可以使用带有括号表示法的安全导航运算符?

properties safe-navigation-operator angular

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

查询什么都不返回

我正在尝试使用该值从我的数据库中获取汽车FK_adId.我尝试使用FK_adId值52 调用方法,并且检查了FK_adId数据库中存在值为52 的汽车.为什么不归还给我?

  public Car getCar(int adId) {
    Car car = null;
    try {
        Class.forName("org.postgresql.Driver");
        if (con != null) {
            ps = con.prepareStatement("SELECT * FROM \"car\" WHERE \"FK_adId\" = ?;");
            ps.setInt(1, adId);
            rs = ps.executeQuery();
            rs.next();
            if (rs.next()) {
                car = new Car(rs.getString("brand"), rs.getString("vin"), rs.getString("condition"), rs.getInt("distanceTraveled"), rs.getInt("age"), rs.getInt("price"), rs.getInt("FK_adId"));
            }
        }
    } catch (Exception ex) {
        System.out.println(ex);
    }
    return car;
}
Run Code Online (Sandbox Code Playgroud)

java postgresql

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