来实习4天了终于开始接触业务了~
今天来了个简单的需求,做数据权限表的增删改查功能。
其中稍微比较复杂的就是一个需要多表联查分页的功能。
控制层Controller
/**
* 分页查询日志列表
*
* @param page 分页参数
* @param name 用户名或昵称模糊查询
* @param type 数据权限类型
* @return
*/
@ApiOperation(value = "根据姓名及类型分页查询", httpMethod = "GET")
@ApiImplicitParams(value = {
@ApiImplicitParam(name = "current",value = "页数",dataType = "Integer",required = true),
@ApiImplicitParam(name = "size",value = "每页数量",dataType = "Integer",required = true),
@ApiImplicitParam(name = "name",value = "根据name模糊查询nickname和username",dataType = "String",required = false),
@ApiImplicitParam(name = "type",value = "数据权限类型 2:区划数据权限' ",dataType = "Integer",required = false)
})
@GetMapping("/page")
public R getPage(Page page, @RequestParam(required = false) String name, @RequestParam(required = false)String type){
return R.ok(sysDataPermissionService.getPage(page, name, type));
}
tip: @ApiOperation与@ApiImplicatParams 一定要写,在前后端接口联调的时候 我们是直接将本地的swagger文档地址给前端看的,这个时候参数描述和是否必须传这些都要写好,不然会被前端骂的(幸好前端小姐姐没有不耐烦,)
SQL及page类
IPage<DataPermissionVo> getPage(Page page, @Param("name") String name, @Param("type")String type);
<select id="getPage" resultType="com.bytefuture.cloud.usercenter.vo.DataPermissionVo">
SELECT SDP.DATA_PERMISSION_TYPE AS dataPermissionType,
SDP.DATA_PERMISSION_VALUE AS dataPermissionValue,
SU.nickname,SU.user_id AS userId
FROM sys_data_permission SDP
LEFT JOIN sys_user SU ON SDP.USER_ID = SU.user_id
WHERE SDP.DEL_FLAG = '0'
<if test="name != null and name != ''">
AND SU.nickname LIKE CONCAT('%', #{name}, '%')
</if>
<if test="type != null and type != ''">
AND SDP.data_permission_type = #{type}
</if>
</select>
● MybatisPlus 传入Page对象时会自动开启分页查询。
● 返回类型记得使用Ipage
● 需要查什么就返回什么,不要select *