一、@ApiImplicitParams注解的详细使用
业务需求:
1.根据服务员类别id(单个id)+服务员星级id(id的list)查询对应的服务员列表
1.controller代码:
点击查看代码
//根据服务员星级+服务员类别,查询对应的服务员list(服务员名称、服务员id)
@GetMapping("/waiter_list")
@ApiOperation("【根据服务员星级+服务员类别查询服务员列表】")
@ApiImplicitParams({
@ApiImplicitParam(name = "waiterCategoryId", value = "服务员类别id", paramType = "query", dataType="String"),
@ApiImplicitParam(name = "waiterGradeIds", value = "服务员星级ids", paramType = "query", dataType="Long",allowMultiple = true,required = true),
@ApiImplicitParam(name = "hotelId", value = "所属酒店id(平台超级管理员可以选择指定酒店查询,酒店管理员默认为自己的酒店id)",required = true, paramType = "query", dataType="String")
})
public Result<List<Map>> waiterList(@ApiIgnore @RequestParam Map<String, Object> params){
List<Map> map = orderService.waiterList(params);
return new Result<List<Map>>().ok(map);
}
2.service代码
点击查看代码
/**
* 根据服务员星级+服务员类别查询服务员列表
* @param params
* @return
*/
List<Map> waiterList(Map<String, Object> params);
3.serviceImpl代码
点击查看代码
@Override
public List<Map> waiterList(Map<String, Object> params) {
log.info("6666666"+params.get("waiterGradeIds"));
List<Map> map=orderDao.getMap(params);
log.info("根据条件查询出的服务员列表信息"+map);
return map;
}
4.dao代码
点击查看代码
/**
* 根据服务员星级+服务员类别查询服务员列表
* @param params
* @return
*/
List<Map> getMap(Map<String, Object> params);
5.dao.xml代码
点击查看代码
<select id="getMap" resultType="java.util.Map">
SELECT
distinct A.id,
A.name
FROM
waiter_user A,
waiter_category B,
waiter_grade C
<where>
<if test="waiterCategoryId != null and waiterCategoryId.trim() != ''">
AND A.waiter_category_id = #{waiterCategoryId}
</if>
<if test="waiterGradeIds != null and waiterGradeIds.trim() != ''">
AND A.waiter_grade_id IN
<foreach item="item" index="index" collection="waiterGradeIds.split(',')" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="hotelId != null and hotelId.trim() != ''">
AND
A.hotel_id = #{hotelId}
AND
B.hotel_id = #{hotelId}
AND
C.hotel_id = #{hotelId}
</if>
</where>
</select>
二、提示
1.前端传递字段
前端传递字段 accountType: a,b,c buType: d,e
2.通过myBatis自带功能foreach,直接把逗号分隔的字符串传到mapper.xml即可,后台不用过多操作,Mapper.xml拼接部分sql如下:
点击查看代码
<if test="q.buType != null and q.buType !='' ">
and bu.bu_type in
<foreach item="item" index="index" collection="q.buType.split(',')" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="q.accountType !=null and q.accountType !='' ">
and coa.mgmt_control_category in
<foreach item="item" index="index" collection="q.accountType.split(',')" open="(" separator="," close=")">
#{item}
</foreach>
</if>
3.注意:
.split(’,’)进行切割,注意是英文输入状态的单引号.