2016-07-08 38 views
0

我使用slick-joda-mapper 2.2slick 3.1play 2.5油滑排序喬達日期

它映射喬達日期沒有任何問題。

import com.github.tototoshi.slick.PostgresJodaSupport._ 

trait QuoteMapping { 
     self: HasDatabaseConfigProvider[JdbcProfile] => 

     import driver.api._ 

     val quotes = TableQuery[Quotes] 

     class Quotes(tag: Tag) extends Table[Quote](tag, "QUOTE") { 
     def id = column[Long]("ID", O.PrimaryKey, O.AutoInc) 

     def startDate = column[LocalDate]("START_DATE") // All OK 
     def endDate = column[LocalDate]("END_DATE") // All OK 

     def pricePerDay = column[Double]("PRICE_PER_DAY") 
     def totalPrice = column[Double]("TOTAL_PRICE") 

     def * = (id.?, startDate, endDate, pricePerDay, totalPrice) <>(Quote.tupled, Quote.unapply) 
     } 

    } 

是否有可能將浮動約會日期排序?

/** Return a page of Quote */ 
def list(page: Int = 0, pageSize: Int = 10, orderBy: Int = 1, filter: String = "%"): Future[Page[(Quote)]] = { 

    val offset = pageSize * page 
    var query = 
    quotes.filter(_.id.asColumnOf[String] like filter.toLowerCase) 
     .drop(offset) 
     .take(pageSize) 

    orderBy match { 
    case 1 => query = query.sortBy(_.id.asc) 
    case 2 => query = query.sortBy(_.startDate.asc) // no .asc method 
    case 3 => query = query.sortBy(_.endDate.asc) // no .asc method 
    case 4 => query = query.sortBy(_.pricePerDay.asc) 
    case 5 => query = query.sortBy(_.totalPrice.asc) 
    case -1 => query = query.sortBy(_.id.desc) 
    case -2 => query = query.sortBy(_.startDate.desc) // no .desc method 
    case -3 => query = query.sortBy(_.endDate.desc) // no .desc method 
    case -4 => query = query.sortBy(_.pricePerDay.desc) 
    case -5 => query = query.sortBy(_.totalPrice.desc) 
    } 

    for { 
    totalRows <- count(filter) 
    list = query.result 
    result <- db.run(list) 
    } yield Page(result, page, offset, totalRows, pageSize) 
} 

回答

0

我只是有壞,而不是進口:

org.joda.time.LocalDate 

是:

java.time.LocalDate 

預期所有的作品,我希望它可以幫助別人