简体   繁体   中英

Grails No converter found capable of converting from type [java.lang.Long] to type [User]

I have two model classes: Book and 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 = {
    }
 }

The login controller takes email and password and puts the user in a session.

      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(){

             }
       }

I am trying to retrieve all entries in Book whose value of "futsal" is equal to user id but I keep getting this error message:

No converter found capable of converting from type [java.lang.Long] to type [fullfinal.User]

I am not getting why and what should be converted here and how do I do it?

您应该传递用于查找书籍的用户对象,而不是ID。

 def books = Book.findAllByFutsal(user)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM