我正在使用Eclipse开发grails版本2.2.1的应用程序,问题是,当我运行应用程序时,我收到下一条消息:
unable to resolve class org.apache.commons.lang3.StringUtils
Run Code Online (Sandbox Code Playgroud)
我将common-lang-jar添加到我的项目中并作为依赖项,但我得到了相同的问题.我能做什么?
我正在尝试更改Grails中控制器名称的默认约定.我的控制器类已命名LongNameInCamelCaseController.Grails约定优于配置设置此控制器的URL映射longNameInCamelCase.我希望这个控制器名称在url友好'long-name-in-camel-case'.
有人已经这样做了吗?
谢谢.
我有一个生产使用的应用程序,当用户进入提案索引页面时,它需要很长时间,有时会超时.我已经将问题缩小为选择所有Proposal对象的SQL语句.问题是Proposal对象有许多图像(byte [])存储在内存中,而这些图像没有在索引页面中使用.这些图像很大,从而导致了问题.
我可以在Grails中优化此查询以删除该页面上不需要的属性或仅添加我在GSP中的属性的不同方法有哪些?
这是控制器代码(scaffolded):
def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
respond Proposal.list(params), model:[proposalInstanceCount: Proposal.count()]
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
我使用Grails 2.4.4作为我的应用程序.我为我的控制器写了一个集成测试.
class UserControllerIntegrationSpec extends IntegrationSpec {
UserController controller = new UserController()
void "test something"() {
when:
controller.request.method = 'POST'
controller.create()
then:
controller.response.status == HttpStatus.OK.value()
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用IntelliJ运行测试时,我得到一个例外:
java.lang.IllegalStateException: Could not find ApplicationContext, configure Grails correctly first
at grails.util.Holders.getApplicationContext(Holders.java:97)
at grails.test.spock.IntegrationSpec.$spock_initializeSharedFields(IntegrationSpec.groovy:41)
Run Code Online (Sandbox Code Playgroud)
当我使用带test-app命令的控制台运行集成测试时没有问题.PS单元测试工作没有问题.
我有一个用户域类,其中包含username,fullName,...等属性和UserRole关联类.
在我的域类中,我在beforeDelete方法上有以下代码
def beforeDelete() {
UserRole.removeAll(this);
}
Run Code Online (Sandbox Code Playgroud)
在UserRole类中,我有像这样的removeAll方法:
static void removeAll(User user) {
executeUpdate 'DELETE FROM UserRole WHERE user=:user', [user: user]
}
Run Code Online (Sandbox Code Playgroud)
对delete方法的调用是在我的UserService类中完成的
def delete(User userInstance){
userInstance.delete()
}
Run Code Online (Sandbox Code Playgroud)
我期待的是:当删除失败时,应该执行回滚,但即使删除失败,也会删除所有UserRole关联.
我错过了什么吗?beforeDelete方法不包含在与userService.delete(User userInstance)方法相同的事务中?
或者我应该将UserRole.removeAll()调用移动到UserService类?
Grails版本:2.3.11
休眠:3.6.10.16
如果我理解正确,我们可以通过将 max 和 offset 值传递给list方法来检索所需数量的特定分页结果。但是,在许多情况下,我们还希望显示 SQL 查询返回的结果总数。根据我的理解,将偏移量和最大值传递给list方法后,SQL 查询仍会在内部返回所有结果,但结果会根据最大值和偏移量值进行修剪。有没有办法在修剪发生之前获得返回的结果总数?
我是Grails的新手.我安装了Spring Security插件,但我想暂时禁用.什么是最简单的方法来禁用此插件(或任何其他Grails插件).
我想创建一个简单的xml节点,然后查看来自http://docs.groovy-lang.org/latest/html/api/groovy/util/Node.html的文档并编写这些代码.
def newbook = new Node(null, 'book', [id:'3'])
newbook.appendNode(new Node(newbook,'title',[id:'BookId3']))
newbook.appendNode(new Node(newbook,'author',[id:'3'],'Harper Lee'))
println groovy.xml.XmlUtil.serialize(newbook)
Run Code Online (Sandbox Code Playgroud)
但输出是
<?xml version="1.0" encoding="UTF-8"?><book id="3">
<title id="BookId3"/>
<title/>
<author id="3">Harper Lee</author>
<author/>
</book>
Run Code Online (Sandbox Code Playgroud)
在我看来,有两个标题标签和作者标签被创建.为什么?
我也试过了
def newbook = new Node(null, 'book', [id:'3'])
newbook.appendNode(new QName('title'),'BookId3')
newbook.appendNode(new QName('author'),[id:'3'],'Harper Lee')
println groovy.xml.XmlUtil.serialize(newbook)
Run Code Online (Sandbox Code Playgroud)
输出是
<?xml version="1.0" encoding="UTF-8"?><book id="3">
<title xmlns="">BookId3</title>
<author xmlns="" id="3">Harper Lee</author>
</book>
Run Code Online (Sandbox Code Playgroud)
现在它看起来不错,但有没有办法删除命名空间?
理想情况下,我希望有这样的东西
<book id="3">
<title>BookId3</title>
<author id="3">Harper Lee</author>
</book>
Run Code Online (Sandbox Code Playgroud)
然后在replaceNode()方法中使用它
我正在尝试将我的 grails 应用程序从 2.0.0 升级到 2.5.5,遇到 groovy-all jar 的未解决的依赖关系。BuildConfig.groovy 中的依赖解析器设置为 ivy。另外,位置 %USERPROFILE%/.grails/ivy-cache/org.codehaus.groovy 包含版本 2.4.5 的 groovy-all.jar
Java设置为JDK7
确切错误:org.codehaus.groovy#groovy-all;2.4.5: 在 org.codehaus.groovy#groovy-all;2.4.5: 'master' 中找不到配置。org.grails#grails-core;2.5.5 编译需要它
BuildConfig.groovy
grails.project.dependency.resolver = "ivy"
repositories {
mavenRepo "link to company specific repo"
mavenCentral()
}
plugins {
runtime ":hibernate4:4.3.10"
runtime ":jquery:1.7.1"
runtime ":resources:1.1.5"
runtime ":bubbling:1.5.1"
runtime ":calendar:1.2.1"
runtime ":code-coverage:1.1.6"
runtime ":jsecurity:0.3"
runtime ":tomcat:7.0.42"
runtime ":webflow:1.3.7"
runtime ":webtest:1.1.5.1"
runtime ":yui:2.8.2.1"
build ":tomcat:7.0.70"
}
Run Code Online (Sandbox Code Playgroud)
请帮忙。如果需要任何其他详细信息,请告诉我。
拥有一个从服务操纵的域,然后尝试保存该域不起作用,即使我使用:save(flush:true, failOnError:true)并validate()返回 true 并hasErrors()返回 false。
我从引导程序进行调用:
def timeKeeperService
def init = { servletContext ->
def TimeKeeper tk = TimeKeeper.findByName('MAIN')?:new TimeKeeper(name:'MAIN').save(flush:true, failOnError:true)
tk = timeKeeperService.initialize()
tk = timeKeeperService.workStart()
Run Code Online (Sandbox Code Playgroud)
域名:
class TimeKeeper {
String name
Date dateCreated
Date dateUpdated
Date workStart
Date workEnd
def initialize() {
println("TimeKeeper initialize...")
workStart = null
workEnd = null
}
def workStart() {
if (workStart == null) {
println("TimeKeeper - workStart")
workEnd = null
workStart = new Date()
} else { …Run Code Online (Sandbox Code Playgroud)