我这样在MySQL中有两行
+---------+---------+
| foo | bar |
+---------+---------+
| | NULL |
| | |
+---------+---------+
Run Code Online (Sandbox Code Playgroud)
空的是空字符串"".
现在我想得到他们两个.我用Criteria与Restrictions.eqOrIsNull()上两列,但它始终只返回一行.
代码是这样的
criteria.add(Restrictions.eqOrIsNull("foo", ""));
.add(Restrictions.eqOrIsNull("bar", ""));
Run Code Online (Sandbox Code Playgroud)
当我仅添加条件时foo,它返回两行.但是bar,因为它只返回第二个,它是空的.
该javadoc的说,Apply an "equal" constraint to the named property. If the value is null, instead apply "is null".所以我会收到这个错误,还是应该以其他方式使用?
更新:
对不起,我太粗心了.医生明确说明了这一点.此方法根据value传递给它而工作,而不是存储在DB中的命名属性的实际值.Github
上的源代码:
public static Criterion eqOrIsNull(String propertyName, Object value) {
return value == null
? isNull( propertyName )
: eq( …Run Code Online (Sandbox Code Playgroud) 有没有办法让Spring通过路径变量的类型将请求映射到不同的方法,如果它们在uri的同一个地方?
例如,
@RequestMapping("/path/{foo}")
@RequestMapping("/path/{id}")
Run Code Online (Sandbox Code Playgroud)
如果foo应该是字符串,id是int,是否可以正确映射而不是查看请求URI?