套餐分页查询
<p>[TOC]</p>
<h5>简要描述</h5>
<ul>
<li>分页查询</li>
</ul>
<h5>接口调用</h5>
<pre><code>async init () {
const params = {
page: this.page,
pageSize: this.pageSize,
name: this.input ? this.input : undefined
}
await getSetmealPage(params).then(res => {
if (String(res.code) === '1') {
this.tableData = res.data.records || []
this.counts = res.data.total
}
}).catch(err => {
this.$message.error('请求出错了:' + err)
})
}</code></pre>
<h5>请求URL</h5>
<ul>
<li><code>[context-path]/setmeal/page</code></li>
</ul>
<h5>请求方式</h5>
<ul>
<li>get </li>
</ul>
<h5>API接口</h5>
<pre><code>const getSetmealPage = (params) => {
return $axios({
url: '/setmeal/page',
method: 'get',
params
})
}</code></pre>
<h5>参数</h5>
<table>
<thead>
<tr>
<th style="text-align: left;">参数名</th>
<th style="text-align: left;">必选</th>
<th style="text-align: left;">类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">page</td>
<td style="text-align: left;">是</td>
<td style="text-align: left;">int</td>
<td>页数</td>
</tr>
<tr>
<td style="text-align: left;">pageSize</td>
<td style="text-align: left;">是</td>
<td style="text-align: left;">int</td>
<td>页面大小</td>
</tr>
<tr>
<td style="text-align: left;">name</td>
<td style="text-align: left;">否</td>
<td style="text-align: left;">varchar(64)</td>
<td>套餐名字</td>
</tr>
</tbody>
</table>
<h5>返回示例</h5>
<pre><code>code: 1
data: {records: [,…], total: 0, size: 10, current: 1, orders: [], optimizeCountSql: true, searchCount: true,…}
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>
<ul>
<li>data有两种返回结果</li>
</ul>
<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>
<h4>后端</h4>
<h5>后端接口请求参数</h5>
<ul>
<li>Spring Boot整合MyBatis实现分页</li>
</ul>
<h5>后端代码</h5>
<pre><code>@GetMapping("/page")
public R<Page> page(int page, int pageSize,String name){
Page<Setmeal> page1 = new Page<>(page,pageSize);
Page<SetmealDto> page2 = new Page<>();
BeanUtils.copyProperties(page1,page2,"records");
LambdaQueryWrapper<Setmeal> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.like(name!=null,Setmeal::getName,name);
queryWrapper.orderByDesc(Setmeal::getUpdateTime);
setmealService.page(page1,queryWrapper);
List<Setmeal> records = page1.getRecords();
List<SetmealDto> collect = records.stream().map(item -> {
SetmealDto setmealDto = new SetmealDto();
Long categoryId = item.getCategoryId();
BeanUtils.copyProperties(item, setmealDto);
Category category = categoryService.getById(categoryId);
setmealDto.setCategoryName(category.getName());
return setmealDto;
}).collect(Collectors.toList());
page2.setRecords(collect);
return R.success(page2);
}</code></pre>