gpt4 book ai didi

grails - 将数据添加到对象后,对象的列表功能不起作用

转载 作者:行者123 更新时间:2023-12-02 15:05:17 25 4
gpt4 key购买 nike

在 Controller 的index操作中,我仍然拥有在Grails中执行create-controller命令时自动生成的代码。在另一个操作中将数据添加到对象后,域对象上的list方法不再起作用。

索引功能:

def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
respond Worksheet.list(params), model:[worksheetInstanceCount: Worksheet.count()]
}

我认为引起此问题的操作是:
def addResults(Map results,id) {
def sql = new Sql(dataSource)
sql.execute("""update domain set results=? where id=?""",new JsonBuilder(results).toString(), id)
}

该数据将以 clob的形式保存到数据库中。除了在数据库中的整数外,在其他地方也可以像这样更新该特定域对象。

现在,列表操作将引发错误消息: argument type mismatch
这是堆栈跟踪:
Error |
2015-11-20 23:14:47,165 [http-bio-8080-exec-2] ERROR property.BasicPropertyAccessor - HHH000123: IllegalArgumentException in class: com.ABET.Results, setter method of property: r_id
Error |
2015-11-20 23:14:47,166 [http-bio-8080-exec-2] ERROR property.BasicPropertyAccessor - HHH000091: Expected type: int, actual value: java.lang.String
Error |
2015-11-20 23:14:47,172 [http-bio-8080-exec-2] ERROR errors.GrailsExceptionResolver - IllegalArgumentException occurred when processing request: [GET] /ABET/worksheet/index
argument type mismatch. Stacktrace follows:
Message: argument type mismatch
Line | Method
->> 43 | <init> in grails.orm.PagedResultList
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 17 | $tt__index in com.ABET.WorksheetController
| 198 | doFilter . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 53 | doFilter . in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
| 62 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run . . . in java.lang.Thread

最佳答案

假定addResults()是罪魁祸首,请尝试使用gorm代替Groovy的Sql

import org.springframework.transaction.annotation.Transactional
...
@Transactional
def addResults(Map results, int id) {
def instance = Domain.get(id)
instance.results = new JsonBuilder(results).toString()
instance.save()
}

请注意,在您的示例中 id没有类型。

关于grails - 将数据添加到对象后,对象的列表功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33839715/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com