实现删除功能:分组下没有视频可以删除分组,有视频不能删除分组。
与前后端交互,如果删除有视频的分组要给前端提示有视频不能删除分组,没有视频的分组删除就提示操作成功。问题是不知道怎么提示有视频不能删除分组?
mapper层:
public int deleteQyVideoGroupById(Long id);
service层:
public int deleteQyVideoGroupById(Long id);
impl层:
public int deleteQyVideoGroupById(Long id) {
QyVideoGroup qyVideoGroup = qyVideoGroupMapper.selectQyVideoGroupById(id);
return qyVideoGroupMapper.deleteQyVideoGroupById(id);
}
xml层:
<delete id="deleteQyVideoGroupById" parameterType="Long">
DELETE from qy_video_group
where qy_video_group.id
not in (select qy_user_video.video_group_id from qy_user_video) and qy_video_group.id=#{id} and is_valid='1'
</delete>
controller层:
@DeleteMapping("/{id}")
public AjaxResult remove(@PathVariable Long id)
{
return toAjax(qyVideoGroupService.deleteQyVideoGroupById(id));
}
toAjax表示:
protected AjaxResult toAjax(int rows)
{
return rows > 0 ? AjaxResult.success() : AjaxResult.error();
}
/**
* 响应返回结果
*
* @param result 结果
* @return 操作结果
*/
protected AjaxResult toAjax(boolean result)
{
return result ? success() : error();
}