简体   繁体   English

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

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

I have two model classes: Book and User. 我有两个模型类: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 = {
    }
 }

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: 我正在尝试检索Book中“ futsal”的值等于用户ID的所有条目,但我不断收到此错误消息:

No converter found capable of converting from type [java.lang.Long] to type [fullfinal.User] 找不到能够将[java.lang.Long]类型转换为[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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring&Couchbase-找不到能够将[java.lang.Long]类型转换为[java.sql.Timestamp]类型的转换器 - Spring & Couchbase - No converter found capable of converting from type [java.lang.Long] to type [java.sql.Timestamp] Spring 数据 Elasticsearch - 找不到能够从类型 [java.lang.Long] 转换为类型 [java.time.Instant] 的转换器 - Spring Data Elasticsearch - No converter found capable of converting from type [java.lang.Long] to type [java.time.Instant] MongoDB 找不到能够从 [java.lang.String] 类型转换为 [java.time.LocalDateTime] 类型的转换器 - MongoDB No converter found capable of converting from type [java.lang.String] to type [java.time.LocalDateTime] 找不到能够从类型转换的转换器 - No converter found capable of converting from type 找不到能够从类型 [java.util.LinkedHashMap 进行转换的转换器<?, ?> ] 输入 [java.lang.String] - Spring 配置服务器 - No converter found capable of converting from type [java.util.LinkedHashMap<?, ?>] to type [java.lang.String] - Spring config server 找不到类型为java.lang.Long的验证器:找不到类型为java.lang.Long的验证器 - No validator could be found for type: java.lang.Long :No validator could be found for type: java.lang.Long 找不到能够从 [java.lang.String] 类型转换为 [@Autowired @ManyToOne @JoinColumn com.papertrue.country.Country] 类型的转换器 - No converter found capable of converting from type [java.lang.String] to type [@Autowired @ManyToOne @JoinColumn com.papertrue.country.Country] Spring MVC“找不到能够将java.lang.String类型转换为org.springframework.core.io.Resource类型的转换器” - Spring MVC “No converter found capable of converting from type java.lang.String to type org.springframework.core.io.Resource” MongoDB映射减少,给出错误“找不到能够从类型java.lang.Boolean转换为类型int的转换器” - MongoDB map reduce, gives error “ No converter found capable of converting from type java.lang.Boolean to type int” org.springframework.core.convert.ConverterNotFoundException:找不到能够从 [java.lang.String] 类型转换为 Model 类型的转换器 - org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type Model
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM