簡體   English   中英

Scala Play Anorm解析器在模型中拋出UnexpectedNullableFound

[英]scala Play Anorm parser throws UnexpectedNullableFound in model

我在運行程序時遇到了Unexpected UnexpectedNullableFound(post.IMAGE)這個錯誤,並且無法識別出什么錯誤,如果有人遇到相同的錯誤或知道錯誤的詳細信息,請在此處提及

而我的數據庫是MySql

我的模特班

case class Post(id: Pk[Long]= NotAssigned, name:String, image:String)

功能

def listAllPostById():List[Post]={
    DB.withConnection{ implicit connection =>
      val listpost =SQL(
          """
          select * from POST 
          """).on(
              ).as(Post.simple.*)
    listpost     
    }

在應用中方法調用

def listAllpost()= Action{
    val post:List[Post]=Post.listAllPostById
    Ok(views.html.allPosts.render(post))
   }

和路線

GET  /allPosts    controllers.Application.listAllpost

和查看頁面

@for(post:Post<- posts){
@post.id
@post.name
@post.image}

簡單的方法

 val simple ={
    get[Pk[Long]]("post.id") ~
    get[String]("post.name")~
    get[String]("post.image") map {
      case id ~ name ~ image => Post(id,name,image)
    }

錯誤

Execution exception

[RuntimeException: UnexpectedNullableFound(post.IMAGE)] 

在線錯誤

   ).as(Post.simple.*)

advnce thnx ..通過prasanth

我認為您的簡單方法有誤。 您必須注意表名和列名,以及在簡單功能中從數據庫中獲取的列的類型。 如果不確定行是否具有所有列的值,則應使用Option,這樣可能會因為數據不可用而捕獲此錯誤。

您應該在簡單的函數中確保有關get [DATA TYPE]或get [Option [DATA TYPE]]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM