小编Rob*_*bin的帖子

在ORMLite中为ApplicationSettings存储多个ArrayLists的最佳方法

现在我试图在应用程序DB的帮助下将应用程序的设置保留给我ORMLite.

那么我的设置由不同String[]或者ArrayList<String>或者一个Map实际上只是一堆Strings.所以我的问题是,我应该为这样的场景使用什么数据类型,也许你也可以给我一个小的code example.

现在我尝试了不同的东西,但我从未对解决方案感到满意.我试过像这样的东西:

private HashMap<String, ArrayList<String>> configurationMap;

private String[] stringArr1;
private String[] stringArr2;

private ArrayList<String> arrList1;
Run Code Online (Sandbox Code Playgroud)

但是当谈到设置时,DB Datatypes我总是认为,"我不想要一个额外的表来存储数据"或"将地图序列化到数据库糟透了......".

也许有人知道如何以一种美观和方便的方式解决这个问题?

java database orm ormlite

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

将List <MyDataType>转换为List <String>的更好方法

我想知道是否没有更好的方法来转换整个ListsCollections我在以下代码示例中显示的方式:

public static List<String> getAllNames(List<Account> allAccounts) {
        List<String> names = new ArrayList<String>(allAccounts.size());
        for (Account account : allAccounts) {
            names.add(account.getName());
        }
        return names;
    }
Run Code Online (Sandbox Code Playgroud)

每次我制作method这样的东西,我都会开始思考,是不是有更好的方法?我首先想到的是可能创造一些解决方案genericsreflections,但这似乎也许有点过大小的,当它涉及到性能也许有点慢?

java

5
推荐指数
2
解决办法
205
查看次数

在Java中处理大型Textfiles

我想知道如果我们假设Filesize大于内存,你如何在Java中操作大文本文件.我搜索了该主题,它表明大多数人都推荐java.nio这样的任务.

不幸的是,我没有找到任何关于如何操作文件的文档.例如,读取每一行,修改它,写它.我尝试过类似的东西,但这不起作用:

    FileChannel fileChannel = null;
    try {
        fileChannel = new RandomAccessFile(file, "rw").getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(256);

        while (fileChannel.read(buffer) != -1) {
            buffer.rewind();
            buffer.flip();
            String nextLine = buffer.asCharBuffer().toString();
            if (replaceBackSlashes) {
                nextLine = nextLine.replace("\\\\", "/");
            }
            if (!(removeEmptyLines && StringUtils.isEmpty(nextLine))) {
                buffer.flip();
                buffer.asCharBuffer().put(nextLine);
            }

            buffer.clear();
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        if (fileChannel != null) {
            try {
                fileChannel.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block …
Run Code Online (Sandbox Code Playgroud)

java text nio

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

没有OutputInterface的Symfony2控制台输出

我试图在Symfony控制台命令中将一些信息打印到控制台.通常你会做这样的事情:

protected function execute(InputInterface $input, OutputInterface $output)
{
    $name = $input->getArgument('name');
    if ($name) {
        $text = 'Hello '.$name;
    } else {
        $text = 'Hello';
    }

    if ($input->getOption('yell')) {
        $text = strtoupper($text);
    }

    $output->writeln($text);
}
Run Code Online (Sandbox Code Playgroud)

有关完整的示例代码 - Symfony文档

不幸的是我无法访问OutputInterface.是否可以将消息打印到控制台?

不幸的是我无法将其传递OutputInterface给我想要打印一些输出的类.

symfony

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

Doctrine查询postgres json(包含)json_array

json_arraydoctrine 的类型作为json数据类型保存到postgres数据库> 9.2.

Postgres 支持包含 json数据类型的许多其他操作.是否有可能使用学说中的功能?

可能需要自定义SQLWalker吗?如上所述这里.另外一个自定义类型支持JSONB会很好.如上所述这里.这将在查询json字段时提高性能.或者是否有自定义库添加json(b)功能或甚至可能使用DQL.

postgresql json symfony doctrine-orm

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

orderBy 几列 - Doctrine QueryBuilder

我想在几个列上使用 orderBY,但它们应该像一列一样。该表看起来像这样:

col1 | col2
5    |
2    |
     | 3
7    |
     | 1
     | 1
Run Code Online (Sandbox Code Playgroud)

结果应该是这样的:

col1 | col2
     | 1
     | 1
2    |
     | 3
5    |
7    |
Run Code Online (Sandbox Code Playgroud)

如果我们要使用原始 SQL,就会有方法,比如使用COALESCE.

但是如何在 Doctrine QueryBuilder 中实现这一点呢?

编辑:

我像这样尝试了 orderBy:

qb->orderBy("COALESCE(col1, col2)", "DESC");
Run Code Online (Sandbox Code Playgroud)

而像这样

qb->add("orderBy", "COALESCE(col1, col2) DESC");
Run Code Online (Sandbox Code Playgroud)

但是两次我都被抛出了以下错误:

[Syntax Error] line 0, col 700: Error: Expected end of string, got '(' 
Run Code Online (Sandbox Code Playgroud)

sql doctrine symfony doctrine-orm

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

Spring Security - 基本HTTP身份验证 - 更改服务器消息

如果您使用基本HTTP身份验证进行身份验证,您将看到如下弹出窗口: 在此输入图像描述

我想改变:服务器说:Spring Security Application到别的东西.但我不知道在哪里改变这个?

spring spring-security http-authentication

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

postgresql jsonb 包含第二级的键:值

postgresql 中是否有可能在第二级查询 key:value

例如一行的 jsonb 字段如下所示:

{
   "something": {
      "v_id": "5544d28431f19", 
      "value": "xyz"
   }, 
   "something_else": {
      "v_id": "5544d28431feb", 
      "value": "abc"
   }
}
Run Code Online (Sandbox Code Playgroud)

我想使用 v_id 值查询这一行,例如:

  SELECT id, jsonb_field
  FROM table_1
  WHERE jsonb_field @> '{{"v_id": "5544d28431feb"}}'
  ;
Run Code Online (Sandbox Code Playgroud)

但是,此查询无效。如何实现这样的查询?

编辑:

根据@CraigRinger 的评论:

这里的重点是我不知道顶级键,我想说“对于任何对象,是否有一个内部对象具有以下键和以下值”。

postgresql json jsonb

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

狂饮获取文件并转发

I have a web-service that gets a file and returns it to the user (based on Symfony). Ever since I used curl to do this.

I just found guzzlehttp and it seems great. However, I do not know how to do this with guzzle without saving the downloaded file (xml or txt) to a local file, read it from the file system a returning it to the user. I want to do this without saving to the file system.

curl symfony guzzle guzzle6

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

Symfony2表单 - 访问父表单的数据

如何访问子表单中父表单的数据?

例如,有产品和类别.产品和类别是多对多的.如果我想编辑类别的所有产品.每个产品的可编辑数据取决于类别.

是否可以通过使用Symfony Forms来实现这一目标?

现在我看不到任何可能性,因为产品没有关于当前类别的信息(因为关系是多对多).

forms symfony-forms symfony

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