小编Cod*_*one的帖子

类型错误:如果没有“new”,则无法调用类构造函数模型

我在一个应用程序中将SequelizeNodeJavaScript一起使用。如您所知,当您执行时,sequelize-init它会创建configmigrationsmodelsseeders文件夹。在models文件夹内,有一个index.js文件(由 cli 生成),它负责从当前文件夹中读取所有模型及其关联:

索引.js

'use strict';

const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const sequelize = require('../database/connection');
const db = {};

fs
  .readdirSync(__dirname)
  .filter(file => {
    return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
  })
  .forEach(file => {
    const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
    db[model.name] = model;
  }); …
Run Code Online (Sandbox Code Playgroud)

javascript node.js sequelize.js ecmascript-6 babeljs

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

Java:堆栈实现中的线程同步

我正在学习ThreadsJava考虑创建一个简单的堆栈来测试Thread synchronization。这是堆栈类:

public class Stack {

    private int counter;
    private String[] storage;
    
    public Stack(final int number) {
        storage = new String[number];
        counter = 0;
    }
    
    public synchronized void push(final String msg) {
        if(counter == storage.length) {
            System.out.println("Counter full");
        } else {
            storage[counter++] = msg;
        }
    }
    
    public synchronized String pop() {
        if(isEmpty()) {
            System.out.println("There is nothing to pop");
            return null;
        } else {
            String lastElement = storage[--counter];
            storage[counter] = null;
            return lastElement;
        }
    } …
Run Code Online (Sandbox Code Playgroud)

java multithreading

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