swift - 快速蒸汽路线错误 - 类型没有成员“保存”
问题描述
我在 routes.swift 中遇到以下错误-如果您需要,我还可以发布其他文件-
import Routing
import Vapor
import FluentSQLite
public func routes(_ router: Router) throws {
router.get { req -> Future <View> in
let Newyorker = Pizza(id: 5, name: "statinisland", description: "impracticaljokers", price: 55)
let Traditional = Pizza(id: 5, name: "rome", description: "pope", price: 55)
return try req.view().render("welcome",["pizza":[Newyorker,Traditional]])
}
router.post(Pizza.self, at: "add") { req, pizza ->
Future<Response> in
return Pizza.save(on:req).map(to:Response.self) { Pizza
in
return req.redirect(to: "/")
}
}
/*Error - Type 'Pizza' has no member 'save'; did you mean 'name'?
Replace 'save' with 'name' */
}
无法弄清楚解决方案。
解决方案
更改Pizza.save(on: req)
为,pizza.save(on: req)
因为您要保存发送到闭包的实例
推荐阅读
- redis - 如何使 AWS Elasticache Redis 在所有只读副本中拆分读取请求?
- php - 如何从 url 隐藏 id 并使其干净 url 我的 .htaccess 文件目录是 /home/evidhya/public_html/tutorials/.htaccess
- c# - 有什么方法可以按照我需要的方式解决 Unity 中的 ODE 系统吗?
- c++ - goto 语句的使用
- python - Pandas 检查多个条件
- java - 在 google 上实施操作
- html - 循环遍历 Laravel Vue js 组件中的数据库表
- arrays - 从另一个矩阵的每个第 i 个元素中减去一个矩阵的每个第 n 个元素
- javascript - axios删除req.body后端未收到
- java - 检测事件时间会话窗口的结束(Apache Flink Java)