有 2 个实体名为Article和Classification。而他们的关系是@ManyToMany。
这是我的问题:如何保存关系?
我的代码如下:
@Entity()
export class Article {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@CreateDateColumn()
createTime: Date;
@UpdateDateColumn()
updateTime: Date;
@Column({
type: 'text',
})
content: string;
@Column({
default: 0,
})
likeAmount: number;
@Column({
default: 0,
})
commentAmount: number;
}
@Entity()
export class Classification {
@PrimaryGeneratedColumn()
id: number;
@CreateDateColumn()
createTime: Date;
@UpdateDateColumn()
updateTime: Date;
@Column()
name: string;
@ManyToMany(type => Article)
@JoinTable()
articles: Article[];
}
Run Code Online (Sandbox Code Playgroud)
我可以保存Article并Classification成功。但我不确定如何保存它们的关系。
我试图通过以下代码保存关系:
async create(dto: ArticleClassificationDto): …Run Code Online (Sandbox Code Playgroud) 我正在使用 Angular 开发我的网站。我想BASE_API为我的项目设置一个取决于prod或dev。因此,我添加了一些代码environment
export const environment = {
production: true,
BASE_API: 'http://localhost:3000/',
};
Run Code Online (Sandbox Code Playgroud)
我想用import { environment } from '@environments/environment'导入而不是import { environment } from '../../../environments/environment';所以我设置tsconfig.app.json如下
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"baseUrl": "./",
"paths": {
"@angular/*": [
"../node_modules/@angular/*"
],
"@environments/*": [
"../src/environments/*"
]
}
},
}
Run Code Online (Sandbox Code Playgroud)
我的项目结构如下
src
app
environments
environment.prod.ts
environment.ts
Run Code Online (Sandbox Code Playgroud)
但是,VSCode 显示:
src/app/user/article/article.service.ts(3,29) 中的错误:错误 TS2307:找不到模块“@environments/environment”。
我该如何解决这个问题?
当我使用函数ngOnInit时,tslint警告我应该实现Oninit.But我可以正常使用函数ngOnInit而不会影响Oninit.Who可以告诉我两种方式之间有什么区别?
我正在使用 Angular+Nest 开发一个网站。我创建了一个服务(Angular),以便客户端可以在项目启动时从服务器获取用户信息(与新鲜相同)。有些动作不需要登录,所以登录是可选的。
我想要的是如果用户已经登录,那么客户端应该发送一个请求来获取用户的信息。
服务器代码如下:
export const RequestUser = createParamDecorator((data, req): RequestUserDTO => {
return req.user;
});
@Controller('auth')
export class AuthController {
@Get('getUserInfoByToken')
async getUserInfoByToken(@RequestUser() user: User): Promise<any> {
if (user) {
return {
nickname: user.nickname,
level: user.level
};
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我发现如果我不添加@UseGuards(AuthGuard())为装饰器,就没有任何回报。但是如果我添加它,当项目开始时,这个请求401作为状态代码返回。然后网页将转到登录页面。
我应该怎么做才能避免这种情况?并非每个操作都需要登录。
我在 VS 代码中自定义了一个片段。代码如下:
"angular2-logger": {
"prefix": "log",
"body": [
"this.log.log('$1');"
],
"description": "??angular2-logger?log??"
}
Run Code Online (Sandbox Code Playgroud)
但是如果想添加更多片段怎么办?谁能给我一个演示?
我是Nest.js的新生。
我的代码如下
@Get('findByFilter/:params')
async findByFilter(@Query() query): Promise<Article[]> {
}
Run Code Online (Sandbox Code Playgroud)
我曾经postman测试过此路由器
http:// localhost:3000 / article / findByFilter / bug?google = 1&baidu = 2
实际上,我可以获得查询结果{ google: '1', baidu: '2' }。但是我不清楚为什么URL有一个字符串'bug'?
如果我删除那个词就像
http:// localhost:3000 / article / findByFilter?google = 1&baidu = 2
然后邮递员将显示statusCode 404。
其实,我不需要这个词bug,如何像自定义路由器一样实现我的目的地http://localhost:3000/article/findByFilter?google=1&baidu=2
这是另一个问题,如何使多个路由器指向一种方法?
我认为,如果A.module导入B.module再B.module导入C.module,那就是A.module导入C.module。这就是许多 Angular 开发人员构建名为 的公共模块的原因Shared.module。
然而,这条规则看起来并不适用于DatePipe. 我构建了一个Shared.module,CommonModule在这个模块中导入和导出。然后我导入Shared.modulein AppModule. 官方文件告诉我它DatePipe属于CommonModule.
不幸的是,浏览器控制台显示错误:NullInjectorError: "StaticInjectorError(AppModule)[AppComponent -> DatePipe]:
您可以在下面的链接中看到代码。
https://stackblitz.com/edit/angular-common-datepipe?embed=1&file=src/app/app.component.ts
谁能帮我解决这个问题?