看到这个链接后,我想尝试Groovy ++,但我有一个担心;
Groovy的所有语法在Groovy ++中都有效吗?
例如,我可以在Groovy中执行此操作:
def list = [1,2]
Run Code Online (Sandbox Code Playgroud)
以上代码在Groovy ++中是否有效?
我正在参加一个grails项目.我在我的应用程序中使用kendo网格.我需要创建一个名为"StatTimings"的域类,它包含两个时间字段startTime和endTime.我不能使用"日期"数据类型为那两个变量因为我需要的时间格式是hh:mm.我不想为此安装任何插件.这是我现在的域名:
class StatTimings{
???? startTime
???? endTime
Date date
AutoPosting autoPosting
Status status
static constraints = {
}
enum Status{ACTIVE,INACTIVE}
enum AutoPosting{SERVICE_CHARGE,STAT_CHARGES,BOTH}
Run Code Online (Sandbox Code Playgroud)
}
有什么方法可以让我的领域只接受时间吗?
Grails 常见问题解答说:
问:如何从src/groovy中的源访问域类?
有时,您正在开发一些生活在src/groovy中的实用程序类,您打算在服务和其他工件中使用它们.但是,由于这些类是由Grails预编译的,因此无法实例化它们并编写类似Book.findByTitle("Groovy in> Action")的内容.但幸运的是,有一种解决方法,因为它可以这样做:
import org.codehaus.groovy.grails.commons.ApplicationHolder
// ...
def book = ApplicationHolder.application.getClassForName("library.Book").findByTitle("Groovy in Action")
应用程序必须在动态Gorm方法正常运行之前完成自举.
但是,似乎我可以直接导入域对象并在我的src/groovy类中使用GORM方法而没有任何问题,例如:
Book.findByTitle("Groovy in Action")
Run Code Online (Sandbox Code Playgroud)
由于不推荐使用ApplicationHolder,这个建议必须过时,但是仍然有理由避免直接从src/groovy使用域类吗?
STS 3.5.0存在问题
https://issuetracker.springsource.com/browse/STS-3792
org.codehaus.groovy.eclipse 2.9.0.xx-201403261719-e43j8在解算器中未知!
这些是我修复它的步骤,它允许我使用eclipse市场
我刚刚开始学习Grails测试,我尝试编写我的第一个grails测试.为此,我创建了一个新的grails项目并创建了一个名为com.rahulserver.SomeController的控制器:
package com.rahulserver
class SomeController {
def index() { }
def someAction(){
}
}
Run Code Online (Sandbox Code Playgroud)
当我创建这个控制器时,grails会自动在test/unit文件夹下创建一个com.rahulserver.SomeControllerSpec.这是我的SomeControllerSpec.groovy:
package com.rahulserver
import grails.test.mixin.TestFor
import spock.lang.Specification
/**
* See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions
*/
@TestFor(SomeController)
class SomeControllerSpec extends Specification {
def setup() {
}
def cleanup() {
}
void testSomeAction() {
assert 1==1
}
}
Run Code Online (Sandbox Code Playgroud)
当我右键单击此类并运行此测试时,我得到以下信息:
Testing started at 5:21 PM ...
|Loading Grails 2.4.3
|Configuring classpath
.
|Environment set to test
....................................
|Running without daemon...
..........................................
|Compiling 1 source files …Run Code Online (Sandbox Code Playgroud) 在Groovy中,我在代码中经常使用地图文字表示法,并对Map的具体实现感到好奇.
在尝试了一些事情之后,这个脚本最能说明我的困惑:
def map = ["A":"B"]
println map // I assume this avoids any lazy evaluation of the map
println map instanceof HashMap // I tried some other impls too
println map.class
Run Code Online (Sandbox Code Playgroud)
并收到此输出:
[A:B]
true
null
Run Code Online (Sandbox Code Playgroud)
这告诉我地图显然是一个HashMap,但getClass方法不想告诉我.
所以我的问题是:为什么getClass返回null,是否有更合适的方法从Groovy获取运行时类信息?
你如何将clojure源文件转换为YAML?我已经使用clj-yaml库在交互式REPL中执行它,但我想自动执行此操作,因此我可以传入输入文件并指定输出,即:
clj2yaml input.clj > output.yml
Run Code Online (Sandbox Code Playgroud) 我是Grails的新手,我继承了现有的应用程序.我有一个大文件message.properties,我想修剪,以删除不再使用的密钥.
在Django中,有一个命令makemessages遍历所有代码库并收集所有需要转换的字符串,将它们添加到消息文件中并注释掉不再存在的条目.Grails有类似的工具吗?如果有帮助,该项目基于1.3.9版本.
我的域层看起来像这样:
@Resource(uri='/product')
class BasicProduct {
String title
String description
Double price
Date creationDate
Date changedDate
static constraints = {
//everything is by default NotNull
title(blank: false, unique: true)
description(blank: false)
price(blank: false, inList: [5,15,25,50,100])
creationDate(min: new Date())
}
}
Run Code Online (Sandbox Code Playgroud)
我的Bootstrap.groovy代码包含:
class BootStrap {
def init = { servletContext ->
new BasicProduct(title: "Product1", description:"blblblblbalablablalbalbablablablablblabalalbllba", price:5).save()
new BasicProduct(title: "Product2", description:"blblblblbalablablalbalbablablablablblabalalbllba", price:75).save()
new BasicProduct(title: "Product3", description:"blblblblbalablablalbalbablablablablblabalalbllba", price:50).save()
new BasicProduct(title: "Product4", description:"blblblblbalablablalbalbablablablablblabalalbllba", price:25).save()
new BasicProduct(title: "Product5", description:"blblblblbalablablalbalbablablablablblabalalbllba", price:15).save()
println "initializing data..."
} …Run Code Online (Sandbox Code Playgroud) 我有一个位于 Maven 中心的图书馆。当我推送一个新版本时,它首先进入 sonatype staging,然后我必须将其推广到生产中。
我想创建一个示例应用程序,它将从 staging 中提取 lib,这样我就可以在将其推广到生产环境之前运行一些测试以及其他一些测试。我会在我的 build.gradle 中使用什么 URL 作为临时存储库?
只是为了澄清我已经尝试使用:https : //oss.sonatype.org/content/repositories/staging/ 但我的项目还没有,只有我已经推广到生产的版本在这个 repo 中。
grails ×5
groovy ×4
java ×2
class ×1
clojure ×1
dictionary ×1
eclipse ×1
gradle ×1
grails-orm ×1
groovy++ ×1
maven ×1
null ×1
sonatype ×1
unit-testing ×1
yaml ×1