根据条件查询分类数据
<p>[TOC]</p>
<h5>简要描述</h5>
<ul>
<li>根据条件查询分类数据</li>
</ul>
<h5>前端页面和服务端的交互过程</h5>
<ul>
<li>页面(front/index.html)发送ajax请求,获取分类数据(菜品分类和套餐分类)</li>
</ul>
<h5>触发事件</h5>
<ul>
<li>初始化数据</li>
</ul>
<h5>接口调用</h5>
<pre><code>Promise.all([categoryListApi(),cartListApi({})]).then(res=>{
//获取分类数据
if(res[0].code === 1){
this.categoryList = res[0].data
if(Array.isArray(res[0].data) && res[0].data.length > 0){
this.categoryId = res[0].data[0].id
if(res[0].data[0].type === 1){
this.getDishList()
}else{
this.getSetmealData()
}
}
}else{
this.$notify({ type:'warning', message:res[0].msg});
}
})</code></pre>
<h5>请求URL</h5>
<ul>
<li><code>[context-path]/category/list</code></li>
</ul>
<h5>请求方式</h5>
<ul>
<li>GET </li>
</ul>
<h5>接口API</h5>
<pre><code>function categoryListApi() {
return $axios({
'url': '/category/list',
'method': 'get',
})
}</code></pre>
<h5>返回示例</h5>
<pre><code>code: 1
data: [{id: "1397844263642378242", type: 1, name: "锅底", sort: 1, createTime: "2021-05-27 09:16:58",…},…]
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>映射Category对象类型参数</li>
</ul>
<h5>后端代码</h5>
<pre><code>@GetMapping("/list")
public R<List<Category>> list(Category category){
LambdaQueryWrapper<Category> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(category.getType()!=null,Category::getType,category.getType());
queryWrapper.orderByAsc(Category::getSort).orderByDesc(Category::getUpdateTime);
List<Category> list = categoryService.list(queryWrapper);
return R.success(list);
}</code></pre>