合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
[TOC] ### api接口按需查询字段 * [ ] 请求方式:http://xxx.sfrg.cn?field=username;age;gender >[danger] field 后面的字段,可以按需要加在后面查询 * [ ] 后端实现: ``` // 查询特定用户 async findOne(ctx) { const {id} = ctx.params // 获取 url?field=xxx const { field } = ctx.query // 将 url 查询字符串 转换为 +field 格式 用于 select 查询字段 const newField = field.split(';') .filter(item => item) .map(item => ` +${item}`).join('') const user = await User.findById(id).select(newField) ctx.body = user || [] } ```