【问题标题】:how to make the mapping for playframework template?如何为 playframework 模板制作映射?
【发布时间】:2014-05-23 19:44:15
【问题描述】:

我使用 slick2.0 而不是 1.0 在playframework2.2模板中:

val 主题 = TableQuery[主题]

@import scala.slick.driver.PostgresDriver.simple._
@main(message) {
@*if(@adlist.size>0){
    @views.html.main("some thing"){<div></div>}*@
<script type='text/javascript'>
    $(function () {
        $('.rating select').barrating({ showSelectedRating:false });
    });
</script>

@slides("sssdfdes")
<div class="list-group">
@for(subitem<-(subject.drop(0).map(i => (i.id, i.name, i.describe,i.sub_resource)).run)){
@topicelement("//localhost/shop/"+subitem._1, subitem._2, 1, subitem._1, subitem._3,subitem._4)

}

</div>

}

错误是:

[info] Loading project definition from G:\testprojects\slickplay\project
[info] Set current project to slickplay (in build file:/G:/testprojects/slickpla
y/)
[info] Compiling 5 Scala sources to G:\testprojects\slickplay\target\scala-2.10\
classes...
[error] G:\testprojects\slickplay\app\views\list_subject.scala.html:23: could no
t find implicit value for parameter session: scala.slick.jdbc.JdbcBackend#Sessio
nDef
[error]                       .map(i => (i.id, i.name, i.describe,i.sub_resource
 )).run)){
[error]
 ^
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 9 s, completed 11/04/2014 4:39:26 AM
actually the problem is:

type mismatch;  found   : scala.slick.lifted.Column[String]  required: String

【问题讨论】:

    标签: scala playframework-2.0 playframework-2.2 slick slick-2.0


    【解决方案1】:

    您没有执行您的查询。您必须使用 .run 执行 Slick 查询,然后才能得到结果:

    @for(subitem<-(subject.drop(0)
                          .map(i => (i.id, i.name, i.describe,i.sub_resource))
                          .run )){
      @topicelement(
        "//localhost/shop/"+subitem._1, subitem._2, 1, subitem._1, subitem._3,subitem._4
      )
    }
    

    【讨论】:

    • [错误] G:\testprojects\slickplay\app\views\list_subject.scala.html:24: value run 不是 scala.slick.lifted.Query[(scala.slick. lifted.Column[Int], s cala.slick.lifted.Column[String], scala.slick.lifted.Column[String], scala.slick.lifted.Column[String]),(Int, String, String, String )]
    • 您缺少来自 Slick 驱动程序的 .simple._ 导入。不确定如何在播放模板中执行此操作。您可能希望将结果传递给模板,而不是查询。
    • 我添加了导入 scala.slick.driver.PostgresDriver.simple._ 查看我更新的问题,但 scala.slick.jdbc.JdbcBackend 仍然存在错误
    • 你需要一个会话。请阅读文档:slick.typesafe.com/doc/2.0.1/…
    • 你知道如何在模板中添加会话吗?
    猜你喜欢
    • 2014-10-16
    • 1970-01-01
    • 1970-01-01
    • 2014-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-14
    • 2021-04-12
    相关资源
    最近更新 更多