首页 > 解决方案 > 快速蒸汽路线错误 - 类型没有成员“保存”

问题描述

我在 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' */  
  }

无法弄清楚解决方案。

标签: swiftroutesvapor

解决方案


更改Pizza.save(on: req)为,pizza.save(on: req)因为您要保存发送到闭包的实例


推荐阅读