接口 http://localhost:3003/dang/ctgymodule/finFirstctgys 没有正常返回,找不到问题的原因
来源:6-2 koa 访问数据库服务器高性能优化——sequelize 数据库连接池

慕仰305485
2023-07-03
到了 AllCtrlRouterLoader 章
接口 http://localhost:3003/dang/ctgymodule/finFirstctgys 返回结果是 Not Found
感觉是 AllCtrlRouterLoader 的问题, 在app。ts中 改成AllRouterLoader
接口 http://localhost:3003/dang/ctgymodule/finFirstctgys 返回的是
{
“msg”: “”,
“code”: 200
}
UserRouter 下的其他接口正常,
CtgyRouter.ts 下
router.get('/finFirstctgys', async (ctx: Context) => {
ctx.body = success(await ctgyDao.findFirstCtgys)
console.log('用了router', ctx.body)
})
打印的结果是
用了router { data: [Function: findFirstCtgys], msg: '', code: 200 }
CtgyDao.ts 下
async findFirstCtgys(): Promise<FirstCtgy[]> {
console.log('这里是CtgyDao')
return await FirstCtgy.findAll({ raw: true })
}
没有打印结果,
我检查了下 FirstCtgy 的模型, 和数据的名字是一一对应的 模型层也是导出的状态,
(名称和视频的不太一样,可能是习惯问题)
@Table({
tableName: 'firstctgy',
})
export default class FirstCtgy extends Model<FirstCtgy> {
@Column({
type: DataTypes.INTEGER,
field: 'firstctgyid',
primaryKey: true,
autoIncrement: true,
})
firstctgyid!: number
@Column({
type: DataTypes.STRING(30),
field: 'name',
allowNull: false,
})
public name!: string
}
写回答
1回答
-
装饰器模型没有加载到引起的
032023-07-04
相似问题