Oss上传文件(有bug)
This commit is contained in:
@@ -7,6 +7,7 @@ import com.bao.dating.pojo.entity.Post;
|
||||
import com.bao.dating.service.PostService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/posts")
|
||||
@@ -16,9 +17,9 @@ public class PostController {
|
||||
private PostService postService;
|
||||
|
||||
@PostMapping
|
||||
public Result<Post> createPost(Post post) {
|
||||
public Result<Post> createPost(@RequestBody Post post, MultipartFile file) {
|
||||
// 调用 Service 层处理发布动态业务逻辑
|
||||
Post result = postService.createPost(post);
|
||||
return Result.success(ResultCode.SUCCESS_REVIEW,"动态发布成功,等待审核。",result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,9 @@ import java.util.List;
|
||||
@Data
|
||||
public class Post {
|
||||
|
||||
private Long postId;
|
||||
private Integer postId;
|
||||
|
||||
private Long userId;
|
||||
private Integer userId;
|
||||
|
||||
private String content;
|
||||
|
||||
|
||||
@@ -11,11 +11,11 @@ import java.time.LocalDateTime;
|
||||
@Data
|
||||
public class PostFavorite {
|
||||
|
||||
private Long favoriteId;
|
||||
private Integer favoriteId;
|
||||
|
||||
private Long userId;
|
||||
private Integer userId;
|
||||
|
||||
private Long postId;
|
||||
private Integer postId;
|
||||
|
||||
private LocalDateTime createdAt;
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@ import java.time.LocalDateTime;
|
||||
*/
|
||||
@Data
|
||||
public class PostLike {
|
||||
private Long likeId;
|
||||
private Integer likeId;
|
||||
|
||||
private Long userId;
|
||||
private Integer userId;
|
||||
|
||||
private Long postId;
|
||||
private Integer postId;
|
||||
|
||||
private LocalDateTime createdAt;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.time.LocalDateTime;
|
||||
@Data
|
||||
public class User {
|
||||
|
||||
private Long userId;
|
||||
private Integer userId;
|
||||
|
||||
private String userName;
|
||||
|
||||
|
||||
@@ -24,6 +24,11 @@ public class PostServiceImpl implements PostService {
|
||||
|
||||
@Override
|
||||
public Post createPost(Post post) {
|
||||
// 检查并确保userId不为空,如果为空则设置默认值
|
||||
if (post.getUserId() == null) {
|
||||
post.setUserId(1); // 设置默认用户ID为1
|
||||
}
|
||||
|
||||
// 处理图片和视频上传到 OSS
|
||||
List<String> mediaOssKeys = new ArrayList<>();
|
||||
|
||||
@@ -62,4 +67,4 @@ public class PostServiceImpl implements PostService {
|
||||
postMapper.insert(post);
|
||||
return post;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
<mapper namespace="com.bao.dating.mapper.PostMapper">
|
||||
<!-- 动态添加 -->
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="postId">
|
||||
INSERT INTO post
|
||||
(user_id, content,
|
||||
<if test="mediaOssKeys != null and mediaOssKeys != ''">
|
||||
@@ -17,9 +17,14 @@
|
||||
is_public, like_count, favorite_count, created_at, updated_at)
|
||||
VALUES
|
||||
(#{userId}, #{content},
|
||||
<if test="mediaOssKeys != null and mediaOssKeys != ''">
|
||||
#{mediaOssKeys, typeHandler=com.bao.dating.handler.ListToVarcharTypeHandler},
|
||||
</if>
|
||||
#{tags, typeHandler=com.bao.dating.handler.ListToVarcharTypeHandler},
|
||||
#{location}, #{isPublic}, 0, 0, #{createdAt}, #{updatedAt})
|
||||
<if test="location != null and location != ''">
|
||||
#{location},
|
||||
</if>
|
||||
#{isPublic}, 0, 0, #{createdAt}, #{updatedAt})
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user