我使用一个需要指定正则表达式的验证器.在验证空字符串的情况下,我不知道如何生成这样的正则表达式.我可以使用什么正则表达式匹配空字符串?
我不知道如何在Groovy中对闭包使用绑定。我写了一个测试代码,并在运行它时说,缺少setBinding作为参数传递的闭包上的方法。
void testMeasurement() {
prepareData(someClosure)
}
def someClosure = {
assertEquals("apple", a)
}
void prepareData(testCase) {
def binding = new Binding()
binding.setVariable("a", "apple")
testCase.setBinding(binding)
testCase.call()
}
Run Code Online (Sandbox Code Playgroud) 我开始在Grails中编写一个简单的命名查询,但它说明了在命名查询的域上缺少方法.难道我做错了什么?我参考了文档,发现代码没有问题.有帮助吗?
我刚刚尝试了文档中的示例.
class Publication {
String title
String author
Date datePublished
Integer numberOfPages
static namedQueries = {
recentPublications {
def now = new Date()
gt 'datePublished', now - 365
}
}
}
Run Code Online (Sandbox Code Playgroud)
调用命名查询就好
Publication.recentPublications()
Run Code Online (Sandbox Code Playgroud)
它抱怨说最近出版的方法遗失了.我使用的是grails 1.3.1