gpt4 book ai didi

java - Grails3:AuthRoleController中的java.lang.Boolean hasErrors()的返回类型与grails.artefact.Controller中的 boolean 值不兼容。

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

我已将我的应用程序从grails 2.5升级到grails 3.3.11。我已经按照所有步骤进行了,一切似乎都很好,但是当我运行该应用程序时。我遇到这个错误:
启动失败:
/home/server-dev/Documents/dev_repo/tms/grails-app/controllers/org/niport/auth/AuthRoleController.groovy:-1:org.niport.auth中java.lang.Boolean hasErrors()的返回类型.AuthRoleController与grails.artefact.Controller中的boolean不兼容
。在[-1:-1] @行-1的第-1列。
1个错误
失败:生成失败,发生异常。

  • 出了什么问题:
    任务':compileGroovy'的执行失败。

  • Compilation failed; see the compiler error output for details.


    任何想法或帮助都会有所帮助,非常感谢
    ------------------------ AuthUserController.groovy ---------------------
         import grails.plugin.springsecurity.SpringSecurityService
    import grails.transaction.Transactional
    import org.niport.com.ComTrainingCenter
    import org.niport.com.ComTrainingCenterService
    import org.niport.com.FileService
    import org.niport.com.TrackerService
    import org.springframework.security.core.context.SecurityContextHolder

    import javax.imageio.ImageIO
    import java.awt.image.BufferedImage

    import static org.springframework.http.HttpStatus.CREATED
    import static org.springframework.http.HttpStatus.OK

    @Transactional(readOnly = true)
    class AuthUserController {
    private static final allowedImageType = ['image/png', 'image/jpeg']

    SpringSecurityService springSecurityService
    AuthUserService authUserService
    TrackerService trackerService
    FileService fileService
    def dateParseFormat,
    currentDate
    AuthUser currentUser
    @Transactional
    save(AuthUser userInstance) {
    if (userInstance == null) {
    flash.error = message(code: "default.message.noRecordFound.label", default: "Error-Save-AuthUser-L21 : Record not found...!")
    redirect(action: "create")
    return
    }


    userInstance.avatarType = params.attachment ? fileService.uploadFile("auth", "auth_user", userInstance?.username, "any", 1, 5000000, params.attachment) : null
    userInstance.createdBy = currentUser?.id
    userInstance.properties["hdCode"] = trackerService.getHdCode(params.password)

    userInstance.validate()
    if (userInstance.hasErrors()) {
    flash.error = "Error-Save-AuthUser-L27 : " + userInstance.errors
    redirect(action: "create", userInstance: userInstance)
    return
    }

    try {
    userInstance.save(failOnError: true)
    }
    catch (Exception e) {
    println "ex-user-sa-L112 : " + e
    flash.error = "Error-Save-AuthUser-L113 : " + e
    redirect(action: "create", userInstance: userInstance)
    return
    }

    request.withFormat {
    form multipartForm {
    flash.success = message(code: "default.message.created", args: [message(code: "user.pageTitle.label", default: "AuthUser"), userInstance.id])
    redirect userInstance
    }
    '*' { respond userInstance, [status: CREATED] }
    }
    }}

    --------------------------AuthRoleController.groovy ----------------------
    mport grails.transaction.Transactional
    import grails.validation.Validateable
    //import grails.artefact.Controller
    //import java.lang.*

    import static org.springframework.http.HttpStatus.CREATED
    import static org.springframework.http.HttpStatus.OK
    class AuthRoleController implements Validateable {

    static allowedMethods = [save: "POST", update: "PUT"]

    def springSecurityService, dateFormat, currentDate, currentUser

    def beforeInterceptor = {
    currentDate = new Date()
    currentUser = springSecurityService.getCurrentUser()
    dateFormat = grailsApplication.config.format.dtp.date
    }
    @Transactional
    def save(AuthRole roleInstance) {
    roleInstance.createdBy=(AuthUser)currentUser
    roleInstance.validate()
    if (roleInstance == null) {
    flash.error = message(code: "default.message.noRecordFound.label", default: "Error-Save-AuthRole-L21 : Record not found...!")
    redirect(action: "create")
    return
    }
    log.info "${roleInstance}";
    if (roleInstance.hasErrors()) {
    flash.error = "Error-Save-AuthRole-L27 : " + roleInstance.errors
    redirect(action: "create", roleInstance: roleInstance)
    return
    }

    try {
    roleInstance.save failOnError: true
    }
    catch (Exception e) {
    flash.error = "Error-Save-AuthRole-L36 : " + e
    redirect(action: "create", roleInstance: roleInstance)
    return
    }

    request.withFormat {
    form multipartForm {
    flash.success = message(code: "default.message.created", args: [message(code: "role.pageTitle.label", default: "AuthRole"), roleInstance.id])
    redirect roleInstance
    }
    '*' { respond roleInstance, [status: CREATED] }
    }
    }

    }

    }

    最佳答案

    class AuthRoleController implements Validateable


    没有充分的理由让 Controller 实现 Validateable特性,这样做会引起问题。
    问题是,您将获得2个名为 hasErrors的方法,一种方法来自 https://github.com/grails/grails-core/blob/1979b62d0ef9ebbaa547c8744263376557a10459/grails-plugin-validation/src/main/groovy/grails/validation/Validateable.groovy#L58,一种方法来自 https://github.com/grails/grails-core/blob/1979b62d0ef9ebbaa547c8744263376557a10459/grails-plugin-controllers/src/main/groovy/grails/artefact/Controller.groovy#L123,它们具有不同的返回类型。

    关于java - Grails3:AuthRoleController中的java.lang.Boolean hasErrors()的返回类型与grails.artefact.Controller中的 boolean 值不兼容。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64064003/

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