查找所有数据
查找数据库所有数据通过 find()
查找
@Get('all')
index() {
return this.typeormService.findAll();
}
async findAll() {
return await this.typeormsEntity.find();
}
查找一条符合条件数据
http://localhost:5500/typeorm/one/2
/**
* 查找一条符合条件的数据
* {id:1}
*/
@Post('one/:id')
getAllOne(@Param() param:TypeormsModule):Promise<TypeormsEntity>{
return this.typeormService.findOne(param)
}
/**
* 查找一条符合条件的数据
* {id:1}
*/
async findOne(param){
return await this.typeormsEntity.findOne(param)
}
查找所有符合条件数据
http://localhost:5500/typeorm/findAll
{
“age”:”q”
}
/**
* 获取所有符合条件的数据
*/
@Post('findAll')
getFindAll(@Body() body){
return this.typeormService.getFindAll(body)
}
/**
* 查找所有符合条件数据
*/
async getFindAll(body){
return await this.typeormsEntity.find(body)
}
查找指定数据 并且 获取数据数量
http://localhost:5500/typeorm/findAndConut
{
“name”:1233
}
@Post('findAndConut')
getFindAndConut(@Body() body){
return this.typeormService.getFindAndConut(body)
}
async getFindAndConut(body){
return await this.typeormsEntity.findAndCount(body).then(res =>{
const [data,count] = res;
return{
data,
count
}
})
}
// 结果
{
"code": 2000,
"message": "请求成功!",
"time": "2021-03-14T06:59:06.520Z",
"data": {
"data": [
{
"id": 1,
"name": "1233",
"age": "q"
},
{
"id": 5,
"name": "1233",
"age": "q"
},
{
"id": 12,
"name": "1233",
"age": ""
}
],
"count": 3
}
}