This commit is contained in:
啊平 2021-02-20 18:44:43 +08:00
parent a70aa31fa4
commit 78b22244cf
5 changed files with 51 additions and 6 deletions

View File

@ -1,5 +1,5 @@
{
"name": "my-midway-project",
"name": "cool-admin-next",
"version": "1.0.0",
"description": "",
"private": true,

View File

@ -13,7 +13,7 @@ import * as cool from 'midwayjs-cool-core';
// 必须,不可移除, cool-admin 官方组件 https://www.cool-js.com
cool,
//redis
]
})
export class ContainerLifeCycle implements ILifeCycle {
@ -22,9 +22,19 @@ export class ContainerLifeCycle implements ILifeCycle {
app: Application;
// 应用启动完成
async onReady(container?: IMidwayContainer) {
this.app.use(async (ctx, next)=>{
console.log('执行了')
});
// this.app.use(async (ctx, next)=>{
// console.log('执行了')
// });
this.app.router.get('/dev', (ctx, next) => {
console.log('进来中间件了');
ctx.status = 200
ctx.body = {
a: 1,
b: 2
};
}, (ctx) => {
console.log('调用路由')
})
}
// 应用停止
async onStop() {

View File

@ -1,8 +1,11 @@
import { Get, Provide, Inject, Query } from '@midwayjs/decorator';
import { CoolController, CoolCache } from 'midwayjs-cool-core';
//import { InjectEntityModel } from '@midwayjs/orm';
import { User } from '../entity/user';
@Provide()
@CoolController()
@CoolController({ api: ['add'], model: User })
export class HomeController {
@Inject('cool:cache')
coolCache: CoolCache;

15
src/dto/test.ts Normal file
View File

@ -0,0 +1,15 @@
import { Rule, RuleType } from "@midwayjs/decorator";
export class UserDTO {
@Rule(RuleType.number().required())
id: number;
@Rule(RuleType.string().required())
firstName: string;
@Rule(RuleType.string().max(10))
lastName: string;
@Rule(RuleType.number().max(60))
age: number;
}

17
src/entity/user.ts Normal file
View File

@ -0,0 +1,17 @@
import { EntityModel } from '@midwayjs/orm';
import { BaseModel } from 'midwayjs-cool-core';
import { Column } from 'typeorm';
import { Rule, RuleType } from "@midwayjs/decorator";
@EntityModel('user')
export class User extends BaseModel {
@Rule(RuleType.number().required())
@Column()
name: string;
@Rule(RuleType.number().max(60))
@Column('int')
age: number;
}