n1ql 和 spel 的可选参数
Optional parameters with n1ql and spel
我有一个包含多个可选参数的查询。
@Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter}" +
"#{(#id != null) ? ' AND META().id = $id' : ''}" +
"#{(#name != null) ? ' AND name like $name' : ''}" +
"#{(#time != null) ? ' AND time = $time' : ''}" +
"#{(#x == null) ? '' : ' AND x = $x' }" +
)
org.springframework.data.domain.ObjectDRP<OjectDRP> findAllAdvanced(
@Param("id") String id,
@Param("name") String name,
@Param("time") Boolean time,
@Param("x") String x
我有这个url:http://localhost:4200/api/objectDRP?page=0&size=10&x=test&sort=lastModifiedDate,desc
服务器给我:
{"msg":"Error evaluating filter. - cause: No value for named parameter $x.","code":5010}
但是如果我将查询更改为:
@Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter}" +
"AND $x is NOT NULL"
"#{(#id != null) ? ' AND META().id = $id' : ''}" +
"#{(#name != null) ? ' AND name like $name' : ''}" +
"#{(#time != null) ? ' AND time = $time' : ''}" +
"#{(#x == null) ? '' : ' AND x = $x' }" +
)
它适用于每组参数:名称、时间、x;姓名、时间;时间...等等
这是我第一次使用 n1ql
和 spel
,所以我不太了解发生了什么。谁能帮我解决这个问题。
2.What 在 n1ql 查询中为空必需参数做些什么?
E.q.:
"SELECT COUNT(*) AS count FROM test_pages WHERE _class = "com.test.testM.test.example.example" AND test = null"
一旦你使用了 named/position 参数,你必须在执行期间传递它们,否则如果执行谓词的那部分,查询 returns 在执行期间会出错。
NULL 表示在 SQL 中未定义与 NULL 的比较始终为假(即 x == NULL,未定义你不能与任何值进行比较)。如果您查询需要这样的比较,它必须使用
x IS MISSING
x IS NOT MISSING
x IS NULL
x IS NOT NULL
x IS VALUED
x IS NOT VALUED
你也可以使用下面的东西
x = IFMISSINGORNULL($x,"")
https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/comparisonops.html
正确的查询将是
SELECT COUNT(1) AS count
FROM `testM`
WHERE _class = "com.test.testL.example.example"
AND test IS NULL;
我有一个包含多个可选参数的查询。
@Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter}" +
"#{(#id != null) ? ' AND META().id = $id' : ''}" +
"#{(#name != null) ? ' AND name like $name' : ''}" +
"#{(#time != null) ? ' AND time = $time' : ''}" +
"#{(#x == null) ? '' : ' AND x = $x' }" +
)
org.springframework.data.domain.ObjectDRP<OjectDRP> findAllAdvanced(
@Param("id") String id,
@Param("name") String name,
@Param("time") Boolean time,
@Param("x") String x
我有这个url:http://localhost:4200/api/objectDRP?page=0&size=10&x=test&sort=lastModifiedDate,desc
服务器给我:
{"msg":"Error evaluating filter. - cause: No value for named parameter $x.","code":5010}
但是如果我将查询更改为:
@Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter}" +
"AND $x is NOT NULL"
"#{(#id != null) ? ' AND META().id = $id' : ''}" +
"#{(#name != null) ? ' AND name like $name' : ''}" +
"#{(#time != null) ? ' AND time = $time' : ''}" +
"#{(#x == null) ? '' : ' AND x = $x' }" +
)
它适用于每组参数:名称、时间、x;姓名、时间;时间...等等
这是我第一次使用 n1ql
和 spel
,所以我不太了解发生了什么。谁能帮我解决这个问题。
2.What 在 n1ql 查询中为空必需参数做些什么?
E.q.:
"SELECT COUNT(*) AS count FROM test_pages WHERE _class = "com.test.testM.test.example.example" AND test = null"
一旦你使用了 named/position 参数,你必须在执行期间传递它们,否则如果执行谓词的那部分,查询 returns 在执行期间会出错。
NULL 表示在 SQL 中未定义与 NULL 的比较始终为假(即 x == NULL,未定义你不能与任何值进行比较)。如果您查询需要这样的比较,它必须使用
x IS MISSING
x IS NOT MISSING
x IS NULL
x IS NOT NULL
x IS VALUED
x IS NOT VALUED
你也可以使用下面的东西
x = IFMISSINGORNULL($x,"")
https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/comparisonops.html
正确的查询将是
SELECT COUNT(1) AS count
FROM `testM`
WHERE _class = "com.test.testL.example.example"
AND test IS NULL;