小编dis*_*ame的帖子

在不同的JRE上运行Java类文件的后果?

在JRE 1.6或1.5上运行JDK 1.4.2中编译的Java类文件有什么后果?

java java1.4

3
推荐指数
2
解决办法
2698
查看次数

PHP preg_replace反向引用导致未定义的常量通知

我正在尝试在code.google.com上使用NameCase php类.当我运行它时,我得到了这个通知,我不明白为什么.

PHP注意:使用未定义的常量Mc - 在namecase.php中假设'Mc'(54):第1行的regexp代码

53   if( preg_match('/\bMac[A-Za-z]{2,}[^aciozj]\b/', $str) || preg_match('/\bMc/', $str) ) {
54     $str = preg_replace("/\b(Ma?c)([A-Za-z]+)/e", "$1.ucfirst('\\2')", $str);
55     // Now correct for "Mac" exceptions
56     $str = preg_replace('/\bMacEvicius/','Macevicius', $str); // Lithuanian
57     $str = preg_replace('/\bMacHado/',   'Machado', $str);    // Portuguese
58     $str = preg_replace('/\bMacHar/',    'Machar', $str);
59     ...
Run Code Online (Sandbox Code Playgroud)

有没有什么可以做的纠正代码,所以它不会产生通知.

谢谢

php regex camelcasing

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

如何在MongoDB中重命名用户?

数据库中有一个用户,应该重命名该用户.如何重命名用户?MongoDB用户管理引用具有方法db.updateUser但我没有看到如何为用户设置新名称.如何更新用户名?TY

db.updateUser(
   "<username>",
   {
     customData : { <any information> },
     roles : [
               { role: "<role>", db: "<database>" } | "<role>",
               ...
             ],
     pwd: "<cleartext password>"
    },
    writeConcern: { <write concern> }
)
Run Code Online (Sandbox Code Playgroud)

rename user-management mongodb

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

MongoDB"eval"执行顺序

如何使用MongoDB shell定义函数并使用它?

在脚本文件中,createusers.js有以下代码用于创建在特定数据库上具有读取角色的用户.

function createReader(database, username, password)
{
db.getSiblingDB(database).createUser({
    user  : username,
    pwd   : password,
    roles : [ { role : "read", db : database } ]
});
}
Run Code Online (Sandbox Code Playgroud)

是否有可能在mongodb shell中执行此功能?以下调用不成功

mongo --eval="createReader('somedb', 'user1', 'pass1')" createusers.js

给出错误createReader没有定义.

javascript shell execution mongodb

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

方法局部内部类

public class Test {
    public static void main(String[] args) {

    }
}

class Outer {
    void aMethod() {
        class MethodLocalInner {
            void bMethod() {
                System.out.println("Inside method-local bMethod");
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

有人能告诉我如何打印消息bMethod吗?

java inner-classes method-invocation

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

array_flip()和utf8

我有一个数组(18键):

$en = array(
    '?' => 'A',
    '?' => 'C',
    '?' => 'E',
    '?' => 'E',
    '?' => 'I',
    'Š' => 'S',
    '?' => 'U',
    '?' => 'U',
    'Ž' => 'Z',
    '?' => 'a',
    '?' => 'c',
    '?' => 'e',
    '?' => 'e',
    '?' => 'i',
    'š' => 's',
    '?' => 'u',
    '?' => 'u',
    'ž' => 'z',
);
Run Code Online (Sandbox Code Playgroud)

这些键是立陶宛simbols(utf8编码).当我这样做$lt = array_flip($en);时返回以下内容:

Array
(
    [A] => ?
    [C] => ?
    [E] => ?
    [I] => ?
    [S] => …
Run Code Online (Sandbox Code Playgroud)

php arrays utf-8 transliteration

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

Java将数据从CSV导入SQL可防止双重输入

我有以下代码.我不确定如何安排它们,以便它可以在将记录添加到SQL数据库之前检查CSV中的条目.问题是我仍然在sql中添加双重记录

try {
        br = new BufferedReader(new FileReader(file));
        String[] data1 = br.readLine().split(cvsSplitBy);

        while ((line = br.readLine()) != null) {
            String queryCheck = "SELECT Count(Name) from DB WHERE Name = ?";

            PreparedStatement st = conn.prepareStatement(queryCheck);
            //value is the data of the name column in the CSV
            st.setString(1, data1[0]);
            ResultSet rs = st.executeQuery();
            boolean recordFound = rs.next();

            if (recordFound) {
                //dont add record

                System.out.println("found " + data1[0]);

            } else {


                String[] data = line.split(cvsSplitBy);

                String sql2 = "INSERT INTO DB (Name, ID, …
Run Code Online (Sandbox Code Playgroud)

java sql csv

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

在AtomicInteger.addAndGet(int)中使用无限循环

在Java的包中java.util.concurrent.atomic AtomicInteger类有一个方法addAndGet(int)

是的

public final int addAndGet(int delta) {
    for (;;) {
        int current = get();
        int next = current + delta;
        if (compareAndSet(current, next))
            return next;
    }
}
Run Code Online (Sandbox Code Playgroud)

为什么它在这里使用无限循环来设置值?

java integer for-loop atomic infinite-loop

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

Postgresql 将字符串放在带有 array_to_string 的引号内

在选择中,我使用了这样的 array_to_string(示例)

array_to_string(array_agg(tag_name),';') tag_names
Run Code Online (Sandbox Code Playgroud)

我得到了结果字符串,"tag1;tag2;tag3;..."但我想将结果字符串作为"'tag1';'tag2';'tag3';...".

我怎样才能在 Postgres 中做到这一点?

arrays postgresql string-aggregation

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

使用提供程序测试组件

我有一个用于服务隔离场景的服务 SoundPanelService(例如https://angular.io/guide/hierarchical-dependency-injection#scenario-service-isolation

@Injectable()
export class SoundPanelService {
  recorded = new Subject<Sound>();

  constructor() {
  }
}
Run Code Online (Sandbox Code Playgroud)

我有 SoundPanelComponent

Component({
  selector: 'app-sound-panel',
  templateUrl: './sound-panel.component.html',
  styleUrls: ['./sound-panel.component.css'],
  providers: [SoundPanelService] // Service isolation 
})
export class SoundPanelComponent implements OnInit {
  recorded = new Subject<Sound>();

  constructor(private soundPanelService: SoundPanelService) {
    this.soundPanelService.recorded.subscribe((data) => {
      this.recorded.next(data);
    });
  }

  ngOnInit() {
  }

}
Run Code Online (Sandbox Code Playgroud)

sound-panel.component.html

<app-sound-player></app-sound-player>
<app-sound-recorder></app-sound-recorder>
Run Code Online (Sandbox Code Playgroud)

SoundPlayer 和 SoundRecorder 通过服务 SoundPanelService 与 soundpanel 通信。

我想测试 SoundPanelComponent

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By …
Run Code Online (Sandbox Code Playgroud)

jasmine karma-runner angular angular8

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