【问题标题】:how to fix play controller error : incompatible types: long cannot be converted to List<General_store>如何修复播放控制器错误:不兼容的类型:long 无法转换为 List<General_store>
【发布时间】:2016-04-15 15:05:29
【问题描述】:

我想获取表列数据“金额”的总和并将其总和作为总和返回。感谢您的帮助

模板代码:

@(tasks: List[General_store], taskForm: Form[General_store])
@main("current balance") {


<div class="col-md-5  col-md-offset-3   client-margin">
    <div class="panel panel-success">
        <div class="panel-heading">
          current Balance
        </div>
        <div class="panel-body"> <br/><br/><br/>
            @for(storedb <- tasks) {



                <p>
                    <b >Balance:</b>@storedb.amount
                </p>


            }

        </div>

    </div>
</div>
}

【问题讨论】:

  • 我嵌入了图像,因此不需要通过超链接来获取所有信息。但是,应将代码添加为文本而不是图像。此外,您应该准确描述您希望代码做什么以及它实际做什么。
  • 好吧,我希望代码在视图上打印 mysql 表列的总和
  • 发布balance.scala.html 模板。我认为你的参数是错误的

标签: playframework playframework-2.2


【解决方案1】:

问题出在模板的参数上。您指定了两个参数 - 商店列表和表单

@(tasks: List[General_store], taskForm: Form[General_store])

但是从您的控制器中,您实际上提供了一个 long (General_store.sumOfStores()) 和一个表单 (taskData)。你看到参数的数量匹配但参数的类型不匹配


解决方案:您必须从以下位置更改控制器代码:

return ok(views.html.balance.render(General_store.sumOfStores(), taskData)

到:

return ok(views.html.balance.render(General_store.sumOfStores(), General_store.all(), taskData)

以及来自

的模板参数定义

@(tasks: List[General_store], taskForm: Form[General_store])

到:

@(totalSum: Long, tasks: List[General_store], taskForm: Form[General_store])

如果您想在页面上显示总和,则必须将此行添加到模板中(例如在&lt;div class="panel-body"&gt; 之后:

&lt;h2&gt;Total sum is: @totalSum&lt;/h2&gt;

【讨论】:

  • 感谢错误不再存在,但结果像往常一样给了我列表,但没有总和
  • 很高兴听到你的消息!如果有帮助,请考虑接受答案 - 就像您之前的问题一样。这是 StackOverflow 的社交协议,如果您不向他们表示感谢,您将不会从人们那里得到太多帮助 :)
  • 哇!真是个好地方,我感谢任何帮助我提高Java技能的人。请分享这个,也许它会帮助像我这样的人。
  • @user3518835 好吧,然后继续接受并upvode(你也会获得声誉)
猜你喜欢
  • 2019-02-26
  • 1970-01-01
  • 2018-10-28
  • 1970-01-01
  • 2019-07-07
  • 2019-06-05
  • 2021-04-27
  • 2019-05-25
  • 1970-01-01
相关资源
最近更新 更多