您好我想在表中手动插入数据,并且我使用了lookupPostParam。
这是发布新新闻中的代码。
postNewsR :: Handler Html
postNewsR = do
now <- liftIO getCurrentTime
newsTitle <- lookupPostParam "title"
newsUrl <- lookupPostParam "news_url"
newsSnapshot <- lookupPostParam "news_snopshot"
newsArea <- lookupPostParam "news_area"
newsSubject <- lookupPostParam "news_subject"
newsContent <- lookupPostParam "news_content"
newsId <- runDB $ insert News newsTitle newsUrl newsSnapshot newsContent False Nothing now Nothing
redirect NewsR
但它给了我以下错误:
Couldn't match type ‘Control.Monad.Trans.Reader.ReaderT
(PersistEntityBackend
(Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Bool
-> Maybe Int
-> UTCTime
-> Maybe UTCTime
-> News))
m0
(Key
(Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Bool
-> Maybe Int
-> UTCTime
-> Maybe UTCTime
-> News))’
with ‘Maybe Data.Text.Internal.Text
-> Maybe Data.Text.Internal.Text
-> Maybe Data.Text.Internal.Text
-> Maybe Data.Text.Internal.Text
-> Bool
-> Maybe a0
-> UTCTime
-> Maybe a1
-> Control.Monad.Trans.Reader.ReaderT
(YesodPersistBackend App) (HandlerT App IO) t0’
Expected type: Maybe Data.Text.Internal.Text
-> Maybe Data.Text.Internal.Text
-> Maybe Data.Text.Internal.Text
-> Maybe Data.Text.Internal.Text
-> Bool
-> Maybe a0
-> UTCTime
-> Maybe a1
-> YesodDB App t0
Actual type: Control.Monad.Trans.Reader.ReaderT
(PersistEntityBackend
(Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Bool
-> Maybe Int
-> UTCTime
-> Maybe UTCTime
-> News))
m0
(Key
(Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Bool
-> Maybe Int
-> UTCTime
-> Maybe UTCTime
-> News))
The function insert is applied to 9 arguments,
but its type ‘(Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Bool
-> Maybe Int
-> UTCTime
-> Maybe UTCTime
-> News)
-> Control.Monad.Trans.Reader.ReaderT
(PersistEntityBackend
(Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Bool
-> Maybe Int
-> UTCTime
-> Maybe UTCTime
-> News))
m0
(Key
(Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Data.Text.Internal.Text
-> Bool
-> Maybe Int
-> UTCTime
-> Maybe UTCTime
-> News))’
我希望你能帮助我,提前谢谢
编辑:
我在我的代码中改变了一些东西。这是更新。从lookupPostParam 到runInputPost
newsTitle <- runInputPost $ ireq textField "title"
newsUrl <- runInputPost $ ireq textField "news_url"
newsSnapshot <- runInputPost $ ireq textField "news_snopshot"
newsArea <- runInputPost $ ireq textField "news_snopshot"
newsSubject <- runInputPost $ ireq textField "news_snopshot"
newsContent <- runInputPost $ ireq textareaField "news_content"
-- Inserting it to the table News
newsId <- insert $ News newsTitle newsUrl newsSnapshot newsContent False Nothing now Nothing
现在它给了我2个错误:
1. Couldn't match type ‘Control.Monad.Trans.Reader.ReaderT
SqlBackend m0’
with ‘HandlerT App IO’
Expected type: HandlerT App IO (Key News)
Actual type: Control.Monad.Trans.Reader.ReaderT
SqlBackend m0 (Key News) …
提前致谢。