我想在执行之前或之后获取由grails生成的Mysql查询.
trainingList = PrivateTraining.findAll(query,parameter)
Run Code Online (Sandbox Code Playgroud)
我想打印由上述语句执行的完整的mysql查询.无论如何打印?
我正在使用Grails作为我的应用程序,我遇到了JSON转换器的问题.
在我的控制器中,我有:
def myObject = [:]
myObject.key = 'value'
render ???
Run Code Online (Sandbox Code Playgroud)
什么是myObject从控制器呈现为JSON的最佳方式?
在我的grails域中,我有一个字段Date,即java.util.Date.
在我的控制器中,我使用SimpleDateFormate从params加载此日期.
确切地说,params.date类似'20/02/2013 02:30 am'.在控制器中我加载如下:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm a"); domainInstance.date = simpleDateFormat.parse(params.date)
执行此语句时,未检测到错误.但是,当保存域实例时会生成错误
[typeMismatch.Domain.date,typeMismatch.date,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable:codes
[无法将'java.lang.String'类型的属性值转换为属性'date'所需的类型'java.util.Date'; 嵌套异常是java.lang.IllegalArgumentException:无法解析日期:Unparseable date:"20/02/2013 02:30 am"]
你能告诉我哪里出了问题吗?我很确定SimpleDateFormat将String解析为Date.为什么它接受为String.
由于依赖性问题,我无法运行我的Grails应用程序.BuildConfig.groovy设置为使用Maven Central,它具有Grails无法找到的依赖项.知道为什么吗?
这是一个我刚刚升级到Grails 2.3的项目,如果这很重要的话.
Loading Grails 2.3.0
Dependency resolver grailsPlugins already defined. Ignoring...
Dependency resolver grailsHome already defined. Ignoring...
| Configuring classpath
:: problems summary ::
:::: WARNINGS
::::::::::::::::::::::::::::::::::::::::::::::
:: UNRESOLVED DEPENDENCIES ::
::::::::::::::::::::::::::::::::::::::::::::::
:: log4j#log4j;1.2.17: configuration not found in log4j#log4j;1.2.17: 'master'. It was required from org.grails.internal#manage;1301 runtime
:: org.jboss.netty#netty;3.2.5.Final: configuration not found in org.jboss.netty#netty;3.2.5.Final: 'compile'. It was required from com.mycompany.event#commons;35.9 compile
:: org.springframework#spring-test;3.2.4.RELEASE: configuration not found in org.springframework#spring-test;3.2.4.RELEASE: 'compile'. It was required from org.grails#grails-plugin-testing;2.3.0 compile
::::::::::::::::::::::::::::::::::::::::::::::
| Error Resolve …Run Code Online (Sandbox Code Playgroud) 如何呈现存储在使用自定义标签的数据库中的图像文件(BLOB),I用于渲染标志,但图像被粉碎并输出为字节数组.
这是我试过的:
def logo = { attrs, body ->
if(session?.companyId && session?.companyId != 'null'){
Company company = Company.findById(session?.companyId)
if (!company || !company?.logo) {
println "No response..."
out <<"<img src='/cdc/static/images/logo.png' width='150' height='70' />"
}
else{
println "Writing..."
out << "<img src='"
out << company?.logo
out << "' width='150' height='70' />"
}
}
else{
println "No response..."
//out <<"<img src='/cdc/static/images/logo.png' width='150' height='70' />"
}
}
Run Code Online (Sandbox Code Playgroud)
输出如下:


公司如何?.logo呈现为图像而不是字节数组?
我有一个URL,然后用户点击以下我需要在新标签页中打开此URL.我怎样才能做到这一点.
我要打开的URL是 http://lhost/pro/app/showusers?p=0&u=90
我的Grails代码如下所示:如何打开将在新选项卡中打开的上述链接
<td><g:link action="showusers" id="${fieldValue(bean: userInstance, field: "name")}">${fieldValue(bean: userInstance, field: "name")}</g:link></td>
Run Code Online (Sandbox Code Playgroud)
更新:
当我点击上面的链接我得到http://lhost/pro/app/showusers/5的URL,但我想显示http://lhost/pro/app/showusers?p=0&u=90为URL.我怎样才能做到这一点 ?
我在Soapui有一个项目:TestSuite1,TestCase1和一些TestStep,如Groovy测试,创建Rep和延迟
我想要做的是使用groovy执行Create Rep TestStep.我试过这个:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
def testCase = testRunner.testCase;
def testStep = testCase.getTestStepAt(0);
def testStep = testCase.getTestStepByName("Create Rep");
def testStep = testCase.testSteps["Delay"];
testRunner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testCase, null);
testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep);
testStep.run(testRunner, testStepContext);
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script15.groovy: 27:
The current scope already contains a variable of the name testStep @ line 27, column 5.
def testStep = testCase.getTestStepByName("");
^ org.codehaus.groovy.syntax.SyntaxException: The current scope already contains a variable of the name testStep @ line …Run Code Online (Sandbox Code Playgroud) def nullString = "String is NOT null"
def check = (nullString != null) ? nullString : "String is null"
def check2 = nullString ? nullString : "String is null"
def check3 = nullString ?: "String is null"
println check
println check2
println check3
Run Code Online (Sandbox Code Playgroud)
告诉我,如果我错了,但上面这三个三元语句都应该做同样的事情,即如果nulString不为null,则打印出"String is not null".如果nullString为null,则打印出"String is null".
而且我认为你们都同意,如果我初始化一个像nullString =""这样的变量,它就不是空的.仅仅因为""不是空的.
但是当使用nullString =""测试上面的代码时,只有第一个打印出"String is not null".另外两个将""解释为null.这是为什么?
(抱歉我的英文,我希望你明白我想说的话)
假设我有这个示例作业(在Groovy w/Java API中):
def set1 = []
def set2 = []
0.upto(10) { set1 << it }
8.upto(20) { set2 << it }
def rdd1 = context.parallelize(set1)
def rdd2 = context.parallelize(set2)
//What next?
Run Code Online (Sandbox Code Playgroud)
如何获得两者之间的差值?我知道union可以创建一个包含这些RDD中所有数据的RDD,但是我该怎么做呢?
我试图在TreeMap中存储字符串的频率,以便我可以获得最常用的字符串,比如说,特定用户.现在我想要做的是编写一个方法,从排序后的地图中返回前n个项目(最常用).
public TreeMap<String,Integer> getKeywords(int n){
//Can check if sorted for efficiency!
println keywords.size();
keywords=keywords.sort{a,b->
//sort the map desc by value
b.value <=> a.value;
}
TreeMap<String,Integer> result=new TreeMap<>();
//need to fill result with first n elements from keywords
return result;
}
Run Code Online (Sandbox Code Playgroud)
我尝试了几种方法,比如使用.each()关键字或迭代其keySet,但没有保留其原始顺序,我最终得到的结果未排序.帮助和提示表示赞赏!!
grails ×6
groovy ×5
grails-orm ×2
apache-spark ×1
grails-2.3 ×1
log4j ×1
maven ×1
null ×1
soapui ×1
treemap ×1