🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] * [ ] 查询包含马的学生 ~~~ // 查询姓名包含马的学生 const { field = '' } = ctx.query const fields = field.split(';').filter(f => f) Student.findAll({ attributes: fields.length === 0 ? '' : fields, where: { name: { [Op.like]:'%马%' } } }) `student`.`name` LIKE '%马%' ~~~ ***** * [ ] 查询姓名**第二个字**为中的学生 ~~~ const { field = '' } = ctx.query const fields = field.split(';').filter(f => f) // 查询名字第二字包含中的学生 const ret = await Student.findAll({ attributes: fields.length === 0 ? '' : fields, where: { name: { [Op.like]:'_中%' } } }) `student`.`name` LIKE '_中%' ~~~ ***** * [ ] 查询姓名三个字的学生 ~~~ const { field = '' } = ctx.query const fields = field.split(';').filter(f => f) // 查询姓名为3个字符的学生 const ret = await Student.findAll({ attributes: fields.length === 0 ? '' : fields, where: { name: { [Op.like]:'___' } } }) `student`.`name` LIKE '___' ~~~