mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2026-03-06 21:57:04 +00:00
111
This commit is contained in:
parent
a70aa31fa4
commit
78b22244cf
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "my-midway-project",
|
||||
"name": "cool-admin-next",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"private": true,
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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
15
src/dto/test.ts
Normal 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
17
src/entity/user.ts
Normal 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;
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user