查询具体菜品/套餐内容
<p>[TOC]</p>
<h5>简要描述</h5>
<ul>
<li>查询具体菜品、套餐内容</li>
</ul>
<h5>前端页面和服务端的交互过程</h5>
<ul>
<li>点击移动端套餐的图片,发现会向后端发送一个get请求</li>
</ul>
<h5>触发事件</h5>
<pre><code>v-model="detailsDialog.show"
:show-confirm-button="false"</code></pre>
<pre><code>v-model="setMealDialog.show"
:show-confirm-button="false"</code></pre>
<h5>接口调用</h5>
<pre><code>const res = await dishListApi({categoryId:this.categoryId,status:1})
if(res.code === 1){
let dishList = res.data
const cartData = this.cartData
if(dishList.length > 0 && cartData.length > 0){
dishList.forEach(dish=>{
cartData.forEach(cart=>{
if(dish.id === cart.dishId){
dish.number = cart.number
}
})
})
}
this.dishList = dishList
}</code></pre>
<h5>请求URL</h5>
<ul>
<li><code>[context-path]/setmeal/dish/${id}</code></li>
</ul>
<h5>请求方式</h5>
<ul>
<li>GET</li>
</ul>
<h5>接口API</h5>
<pre><code>function setMealDishDetailsApi(id) {
return $axios({
'url': `/setmeal/dish/${id}`,
'method': 'get',
})
}</code></pre>
<h5>返回示例</h5>
<pre><code>code: 1
data: [,…]
map: {}
msg: null</code></pre>
<h5>返回参数说明</h5>
<table>
<thead>
<tr>
<th style="text-align: left;">参数名</th>
<th style="text-align: left;">类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">code</td>
<td style="text-align: left;">int</td>
<td>返回码,1:成功;0或其他:失败</td>
</tr>
<tr>
<td style="text-align: left;">data</td>
<td style="text-align: left;">object</td>
<td>返回数据</td>
</tr>
<tr>
<td style="text-align: left;">map</td>
<td style="text-align: left;">map</td>
<td>动态数据</td>
</tr>
<tr>
<td style="text-align: left;">msg</td>
<td style="text-align: left;">string</td>
<td>错误信息</td>
</tr>
</tbody>
</table>
<h5>备注</h5>
<p>data有两种返回值</p>
<pre><code>public static <T> R<T> success(T object) {
R<T> r = new R<T>();
r.data = object;
r.code = 1;
return r;
}
public static <T> R<T> error(String msg) {
R r = new R();
r.msg = msg;
r.code = 0;
return r;
}</code></pre>
<h5>后端接口请求参数</h5>
<ul>
<li>通过 @PathVariable 将 URL 中占位符参数“id”绑定到控制器处理入参</li>
</ul>
<h5>后端代码</h5>
<pre><code> @GetMapping("/dish/{id}")
public R<List<DishDto>> setMealDishDetails(@PathVariable("id") Long SetmealId){
LambdaQueryWrapper<SetmealDish> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SetmealDish::getSetmealId,SetmealId);
List<SetmealDish> list = setmealDishService.list(queryWrapper);
List<DishDto> dishDtos = list.stream().map((setmealDish) -> {
DishDto dishDto = new DishDto();
BeanUtils.copyProperties(setmealDish, dishDto);
Long dishId = setmealDish.getDishId();
Dish dish = dishService.getById(dishId);
BeanUtils.copyProperties(dish, dishDto);
return dishDto;
}).collect(Collectors.toList());
return R.success(dishDtos);
}
}</code></pre>