【问题标题】:Grails No converter found capable of converting from type [java.lang.Long] to type [User]Grails 没有找到能够从 [java.lang.Long] 类型转换为 [User] 类型的转换器
【发布时间】:2018-06-07 15:56:28
【问题描述】:

我有两个模型类:Book 和 User。

    class Book {
         Date date
         String time
         User  futsal
         String email

         static constraints = {
         }
    }


class User {
    String fullName
    String futsalName
    String location
    String email
    String password
    String myUpload

    static constraints = {
    }
 }

登录控制器获取电子邮件和密码并将用户置于会话中。

      package fullfinal

      class LoginController {

                def index() { }

                def login(){
                   def email = params.email
                   def password = params.password

                   def user = User.findByEmailAndPassword(email,password);

                   if(user!=null){
                         session["u"] = user
                    }

                   def id = user.id


                   def books = Book.findAllByFutsal(id)

                  render(view:"dashboard" ,model:[u:session.u])
                  }

            def dashboard(){

             }
       }

我正在尝试检索 Book 中“五人制足球”值等于用户 ID 的所有条目,但我不断收到以下错误消息:

没有找到能够从 [java.lang.Long] 类型转换为 [fullfinal.User] 类型的转换器

我不明白为什么和应该在这里转换什么,我该怎么做?

【问题讨论】:

  • 您能否提供您的错误消息的完整堆栈跟踪?谢谢!

标签: java mysql grails groovy


【解决方案1】:

您应该传递用户对象来查找书籍而不是 id。

 def books = Book.findAllByFutsal(user)

【讨论】:

    猜你喜欢
    • 2014-01-28
    • 2018-02-15
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    • 2019-10-20
    • 2019-02-10
    • 2021-09-22
    • 1970-01-01
    相关资源
    最近更新 更多