将删除动态优化为批量删除动态
This commit is contained in:
@@ -45,14 +45,14 @@ public class PostController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除动态
|
||||
* 批量删除动态
|
||||
*
|
||||
* @param postId 动态ID
|
||||
* @param postIds 动态ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping("/{postId}")
|
||||
public Result<String> deleteById(@PathVariable Long postId){
|
||||
postService.deletePostById(postId);
|
||||
@DeleteMapping
|
||||
public Result<String> deleteById(@RequestParam List<Long> postIds){
|
||||
postService.deletePostById(postIds);
|
||||
return Result.success(ResultCode.SUCCESS_DELETE, "动态删除成功", null);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.bao.dating.pojo.entity.Post;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PostMapper {
|
||||
/**
|
||||
@@ -16,9 +18,9 @@ public interface PostMapper {
|
||||
/**
|
||||
* 根据ID删除动态
|
||||
*
|
||||
* @param postId 动态ID
|
||||
* @param postIds 动态ID
|
||||
*/
|
||||
void deletePostById(@Param("postId") Long postId);
|
||||
void deletePostByIds(@Param("postIds") List<Long> postIds);
|
||||
|
||||
/**
|
||||
* 根据ID查询动态
|
||||
|
||||
@@ -25,10 +25,10 @@ public interface PostService {
|
||||
|
||||
/**
|
||||
* 删除动态
|
||||
* @param postId 动态ID
|
||||
* @param postIds 动态ID
|
||||
* @return 删除的动态对象
|
||||
*/
|
||||
void deletePostById(Long postId);
|
||||
void deletePostById(List<Long> postIds);
|
||||
|
||||
/**
|
||||
* 查询动态详情(用于编辑)
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.bao.dating.util.FileUtil;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -159,12 +160,14 @@ public class PostServiceImpl implements PostService {
|
||||
/**
|
||||
* 删除动态
|
||||
*
|
||||
* @param postId 动态ID
|
||||
* @param postIds 动态ID
|
||||
* @return 删除的动态对象
|
||||
*/
|
||||
@Override
|
||||
public void deletePostById(Long postId) {
|
||||
postMapper.deletePostById(postId);
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deletePostById(List<Long> postIds) {
|
||||
// 批量删除动态
|
||||
postMapper.deletePostByIds(postIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,8 +29,23 @@
|
||||
</insert>
|
||||
|
||||
<!--动态删除-->
|
||||
<delete id="deletePostById">
|
||||
DELETE FROM post WHERE post_id = #{postId}
|
||||
<delete id="deletePostByIds">
|
||||
DELETE FROM post WHERE post_id IN
|
||||
<foreach item="postId" index="index" collection="postIds" separator="," open="(" close=")">
|
||||
#{postId}
|
||||
</foreach>
|
||||
</delete>
|
||||
<!--删除收藏记录-->
|
||||
<delete id="1">
|
||||
DELETE FROM post_favorite WHERE post_id = #{postId}
|
||||
</delete>
|
||||
<!--删除点赞记录-->
|
||||
<delete id="2">
|
||||
DELETE FROM post_like WHERE post_id = #{postId}
|
||||
</delete>
|
||||
<!--动态评论删除-->
|
||||
<delete id="3">
|
||||
DELETE FROM comments WHERE post_id = #{postId}
|
||||
</delete>
|
||||
|
||||
<!--动态查询-->
|
||||
|
||||
Reference in New Issue
Block a user