Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java hibernate中字符串字段与字符串数组的交集_Java_Sql_Hibernate - Fatal编程技术网

Java hibernate中字符串字段与字符串数组的交集

Java hibernate中字符串字段与字符串数组的交集,java,sql,hibernate,Java,Sql,Hibernate,我有一个表,它驻留一个由逗号分隔的字符串字段,还有一个字符串数组。我想在字符串数组中查找这个逗号分隔的字符串字段。我无法标记字符串字段,以便通过“IN”子句查看字符串数组内部。示例如下: String feild = "inbox, outbox, draft, sent"; String[] strArray = ["inbox, "outbox", "sent", "web", "software"]; 如何获取字段字符串与字符串数组的交点?您可以使用: Criterion c = nul

我有一个表,它驻留一个由逗号分隔的字符串字段,还有一个字符串数组。我想在字符串数组中查找这个逗号分隔的字符串字段。我无法标记字符串字段,以便通过“IN”子句查看字符串数组内部。示例如下:

String feild = "inbox, outbox, draft, sent";
String[] strArray = ["inbox, "outbox", "sent", "web", "software"];
如何获取字段字符串与字符串数组的交点?

您可以使用:

Criterion c = null;
for(String s : strArray){
    if(c!=null){
        c = Restrictions.like("field","%"+s+"%");
    else {
        c = Restrictions.or(c,Restrictions.like("field","%"+s+"%"));
    }
}

这是一种低效的方法,但却是一种解决方案。

虽然存储在表中的字符串是逗号分隔的,但必须将其视为字符串。在这种情况下,我不认为你能在中找到我们。在这种情况下,我应该采取什么方法,因为我找不到任何解决办法。实际上,我并不是想用“IN”来准确地查询它。我想用类似的方法查询它。因为数据是一个字符串,所以您可以尝试
LIKE
。我尝试了LIKE,但它无法将feild string中的每个单词与字符串数组匹配。像这样的交叉路口是不可能的。我试着用这种方法解决这个问题,但代价很高。考虑一个必须在长字符串字段中搜索的大字符串数组。这是一个没有效率的解决方案:)