mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2026-03-17 03:03:50 +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",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
@ -13,7 +13,7 @@ import * as cool from 'midwayjs-cool-core';
|
|||||||
// 必须,不可移除, cool-admin 官方组件 https://www.cool-js.com
|
// 必须,不可移除, cool-admin 官方组件 https://www.cool-js.com
|
||||||
cool,
|
cool,
|
||||||
//redis
|
//redis
|
||||||
|
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class ContainerLifeCycle implements ILifeCycle {
|
export class ContainerLifeCycle implements ILifeCycle {
|
||||||
@ -22,9 +22,19 @@ export class ContainerLifeCycle implements ILifeCycle {
|
|||||||
app: Application;
|
app: Application;
|
||||||
// 应用启动完成
|
// 应用启动完成
|
||||||
async onReady(container?: IMidwayContainer) {
|
async onReady(container?: IMidwayContainer) {
|
||||||
this.app.use(async (ctx, next)=>{
|
// this.app.use(async (ctx, next)=>{
|
||||||
console.log('执行了')
|
// 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() {
|
async onStop() {
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
import { Get, Provide, Inject, Query } from '@midwayjs/decorator';
|
import { Get, Provide, Inject, Query } from '@midwayjs/decorator';
|
||||||
import { CoolController, CoolCache } from 'midwayjs-cool-core';
|
import { CoolController, CoolCache } from 'midwayjs-cool-core';
|
||||||
|
//import { InjectEntityModel } from '@midwayjs/orm';
|
||||||
|
import { User } from '../entity/user';
|
||||||
|
|
||||||
|
|
||||||
@Provide()
|
@Provide()
|
||||||
@CoolController()
|
@CoolController({ api: ['add'], model: User })
|
||||||
export class HomeController {
|
export class HomeController {
|
||||||
@Inject('cool:cache')
|
@Inject('cool:cache')
|
||||||
coolCache: CoolCache;
|
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