add. post相关数据结构

This commit is contained in:
many2many 2024-05-21 15:22:47 +08:00
parent 4249468d27
commit fdef2eaa38
39 changed files with 934 additions and 1 deletions

View File

@ -0,0 +1,21 @@
package com.lk.paopao.dto;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Value;
import java.io.Serializable;
/**
* DTO for {@link com.lk.paopao.entity.CommentContent}
*/
@Value
public class CommentContentDto implements Serializable {
Long id;
String content;
Byte type;
Integer sort;
@JsonSerialize(using = MillisecondToSecondSerializer.class)
Long createdOn;
@JsonSerialize(using = MillisecondToSecondSerializer.class)
Long modifiedOn;
}

View File

@ -0,0 +1,29 @@
package com.lk.paopao.dto;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Value;
import java.io.Serializable;
import java.util.List;
/**
* DTO for {@link com.lk.paopao.entity.Comment}
*/
@Value
public class CommentDto implements Serializable {
Long id;
Long userId;
Long postId;
String ip;
String ipLoc;
Boolean isEssence;
Integer replyCount;
Integer thumbsUpCount;
Integer thumbsDownCount;
@JsonSerialize(using = MillisecondToSecondSerializer.class)
Long createdOn;
@JsonSerialize(using = MillisecondToSecondSerializer.class)
Long modifiedOn;
UserDto user;
List<CommentContentDto> contents;
}

View File

@ -0,0 +1,27 @@
package com.lk.paopao.dto;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Value;
@Value
public class CommentReplyDto {
Long id;
@JsonSerialize(using = MillisecondToSecondSerializer.class)
Long createdOn;
@JsonSerialize(using = MillisecondToSecondSerializer.class)
Long modifiedOn;
Long commentId;
UserDto user;
String content;
String ip;
String ipLoc;
Integer thumbsUpCount;
Integer thumbsDownCount;
}

View File

@ -0,0 +1,34 @@
package com.lk.paopao.dto;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
/**
* 将毫秒转换为秒的Json序列化器
* 此序列化器将数值类型的毫秒数转换为对应的秒数进行JSON序列化
*/
public class MillisecondToSecondSerializer extends JsonSerializer<Number> {
/**
* 序列化方法将输入的毫秒数转换为秒数后写入JSON生成器
*
* @param value 需要序列化的毫秒数类型为Number
* @param gen JSON生成器用于输出序列化后的结果
* @param serializers 序列化提供者提供序列化过程所需的额外服务
* @throws IOException 如果在序列化过程中发生IO异常
*/
@Override
public void serialize(Number value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
if (value != null) {
// 将输入的毫秒数转换为秒数
long microseconds = value.longValue();
long seconds = TimeUnit.MILLISECONDS.toSeconds(microseconds);
// 将转换后的秒数写入JSON生成器
gen.writeNumber(seconds);
}
}
}

View File

@ -0,0 +1,16 @@
package com.lk.paopao.dto;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Value;
@Value
public class PostCollectionDto {
Long id;
PostDto post;
UserDto user;
@JsonSerialize(using = MillisecondToSecondSerializer.class)
Long createdOn;
@JsonSerialize(using = MillisecondToSecondSerializer.class)
Long modifiedOn;
}

View File

@ -0,0 +1,22 @@
package com.lk.paopao.dto;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Value;
import java.io.Serializable;
/**
* DTO for {@link com.lk.paopao.entity.PostContent}
*/
@Value
public class PostContentDto implements Serializable {
Long id;
Long postId;
String content;
Byte type;
Integer sort;
@JsonSerialize(using = MillisecondToSecondSerializer.class)
Long createdOn;
@JsonSerialize(using = MillisecondToSecondSerializer.class)
Long modifiedOn;
}

View File

@ -0,0 +1,37 @@
package com.lk.paopao.dto;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Value;
import java.io.Serializable;
import java.util.List;
/**
* DTO for {@link com.lk.paopao.entity.Post}
*/
@Value
public class PostDto implements Serializable {
Long id;
Long userId;
Long commentCount;
Long collectionCount;
Long upvoteCount;
Long shareCount;
Byte visibility;
Boolean isTop;
Boolean isEssence;
Boolean isLock;
Long latestRepliedOn;
String tags;
Long attachmentPrice;
String ip;
String ipLoc;
@JsonSerialize(using = MillisecondToSecondSerializer.class)
Long createdOn;
@JsonSerialize(using = MillisecondToSecondSerializer.class)
Long modifiedOn;
Long deletedOn;
Byte isDel;
UserDto user;
List<PostContentDto> contents;
}

View File

@ -0,0 +1,15 @@
package com.lk.paopao.dto;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Value;
@Value
public class PostStarDto {
Long id;
PostDto post;
UserDto user;
@JsonSerialize(using = MillisecondToSecondSerializer.class)
Long createdOn;
@JsonSerialize(using = MillisecondToSecondSerializer.class)
Long modifiedOn;
}

View File

@ -0,0 +1,19 @@
package com.lk.paopao.dto;
import lombok.Value;
import java.io.Serializable;
/**
* DTO for {@link com.lk.paopao.entity.Tag}
*/
@Value
public class TagDto implements Serializable {
Long id;
Long userId;
UserDto user;
String tag;
Long quoteNum;
Long createdOn;
Long modifiedOn;
}

View File

@ -0,0 +1,12 @@
package com.lk.paopao.dto.rest.request;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
public class ContentInPostRequest {
private String content;
private Integer sort;
private Byte type;
}

View File

@ -0,0 +1,20 @@
package com.lk.paopao.dto.rest.request;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Setter
@Getter
public class PostRequest {
private Long attachmentPrice;
private Byte visibility;
//帖子内容列表
List<ContentInPostRequest> contents;
// #标签列表
List<String> tags;
// @用户列表
List<String> users;
}

View File

@ -0,0 +1,35 @@
package com.lk.paopao.dto.rest.response;
import lombok.Getter;
import java.io.Serializable;
import java.util.List;
/**
* @description 分页数据
* @param <T>
*/
@Getter
public class Paged<T> implements Serializable {
List<T> list;
Pager pager;
public Paged(List<T> list, Long totalRows, Integer page, Integer pageSize){
this.list = list;
pager = new Pager(page, pageSize, totalRows);
}
@Getter
public class Pager implements Serializable{
Integer page;
Integer pageSize;
Long totalRows;
public Pager(Integer page, Integer pageSize, Long totalRows){
this.page = page;
this.pageSize = pageSize;
this.totalRows = totalRows;
}
}
}

View File

@ -0,0 +1,43 @@
package com.lk.paopao.entity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.io.Serializable;
@Getter
@Setter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseAuditingEntity implements Serializable {
// 主键ID
@Comment("ID")
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Comment("创建时间")
@Column(name = "created_on", nullable = false)
@CreatedDate
private Long createdOn;
@Comment("修改时间")
@LastModifiedDate
@Column(name = "modified_on", nullable = false)
private Long modifiedOn;
@Comment("删除时间")
@Column(name = "deleted_on")
private Long deletedOn;
@Comment("是否删除 0 为未删除、1 为已删除")
@Column(name = "is_del")
private byte isDel = 0;
}

View File

@ -0,0 +1,66 @@
package com.lk.paopao.entity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.util.List;
@Getter
@Setter
@org.hibernate.annotations.Comment("评论")
@Entity
@Table(name = "p_comment", indexes = {
@Index(name = "idx_comment_post_id", columnList = "post_id"),
@Index(name = "idx_comment_user_id", columnList = "user_id")
})
@EntityListeners(AuditingEntityListener.class)
public class Comment extends BaseAuditingEntity{
@Version
private Long version;
@org.hibernate.annotations.Comment("POST ID")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id", nullable = false)
private Post post;
@org.hibernate.annotations.Comment("用户ID")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private User user;
@OneToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY,mappedBy = "comment")
private List<CommentContent> contents;
@org.hibernate.annotations.Comment("IP地址")
@Column(name = "ip", length = 15)
private String ip;
@org.hibernate.annotations.Comment("IP城市地址")
@Column(name = "ip_loc", length = 64)
private String ipLoc;
@org.hibernate.annotations.Comment("是否精选")
@ColumnDefault("0")
@Column(name = "is_essence", nullable = false)
private Boolean isEssence = false;
@org.hibernate.annotations.Comment("回复数")
@ColumnDefault("0")
@Column(name = "reply_count", nullable = false)
private Integer replyCount = 0;
@org.hibernate.annotations.Comment("点赞数")
@ColumnDefault("0")
@Column(name = "thumbs_up_count", nullable = false)
private Integer thumbsUpCount = 0;
@org.hibernate.annotations.Comment("点踩数")
@ColumnDefault("0")
@Column(name = "thumbs_down_count", nullable = false)
private Integer thumbsDownCount = 0;
}

View File

@ -0,0 +1,49 @@
package com.lk.paopao.entity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@Getter
@Setter
@Comment("评论内容")
@Entity
@Table(name = "p_comment_content", indexes = {
@Index(name = "idx_comment_content_comment_id", columnList = "comment_id"),
@Index(name = "idx_comment_content_user_id", columnList = "user_id"),
@Index(name = "idx_comment_content_type", columnList = "type"),
@Index(name = "idx_comment_content_sort", columnList = "sort")
})
@EntityListeners(AuditingEntityListener.class)
public class CommentContent extends BaseAuditingEntity{
@Comment("评论ID")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "comment_id")
private com.lk.paopao.entity.Comment comment;
@Comment("用户ID")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;
@Comment("内容")
@ColumnDefault("")
@Column(name = "content", nullable = false, length = 4000)
private String content;
@Comment("类型1标题2文字段落3图片地址4视频地址5语音地址6链接地址")
@ColumnDefault("2")
@Column(name = "type", nullable = false)
private Byte type = 2;
@Comment("排序,越小越靠前")
@ColumnDefault("100")
@Column(name = "sort", nullable = false)
private Integer sort = 100;
}

View File

@ -0,0 +1,53 @@
package com.lk.paopao.entity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.Comment;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@Getter
@Setter
@Comment("评论回复")
@Entity
@Table(name = "p_comment_reply", indexes = {
@Index(name = "idx_comment_reply_comment_id", columnList = "comment_id")
})
@EntityListeners(AuditingEntityListener.class)
public class CommentReply extends BaseAuditingEntity{
@Version
private Long version;
@Comment("评论ID")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "comment_id", nullable = false)
private com.lk.paopao.entity.Comment comment;
@Comment("用户ID")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private User user;
@Comment("内容")
@Column(name = "content", nullable = false, length = 4000)
private String content;
@Comment("IP地址")
@Column(name = "ip", length = 15)
private String ip;
@Comment("IP城市地址")
@Column(name = "ip_loc", length = 64)
private String ipLoc;
@Comment("点赞数")
@ColumnDefault("0")
@Column(name = "thumbs_up_count", nullable = false)
private Integer thumbsUpCount = 0;
@Comment("点踩数")
@ColumnDefault("0")
@Column(name = "thumbs_down_count", nullable = false)
private Integer thumbsDownCount = 0;
}

View File

@ -0,0 +1,93 @@
package com.lk.paopao.entity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.Comment;
import java.util.List;
@Getter
@Setter
@Comment("冒泡/动态/文章")
@Entity
@Table(name = "p_post", indexes = {
@Index(name = "idx_post_user_id", columnList = "user_id"),
@Index(name = "idx_post_visibility", columnList = "visibility")
})
public class Post extends BaseAuditingEntity{
@Version
private Long version;
@Comment("用户ID")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;
@OneToMany(mappedBy = "post", cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
private List<PostContent> contents;
@Comment("评论数")
@ColumnDefault("0")
@Column(name = "comment_count", nullable = false)
private Long commentCount = 0L;
@Comment("收藏数")
@ColumnDefault("0")
@Column(name = "collection_count", nullable = false)
private Long collectionCount = 0L;
@Comment("点赞数")
@ColumnDefault("0")
@Column(name = "upvote_count", nullable = false)
private Long upvoteCount = 0L;
@Comment("分享数")
@ColumnDefault("0")
@Column(name = "share_count", nullable = false)
private Long shareCount = 0L;
@Comment("可见性: 0私密 10充电可见 20订阅可见 30保留 40保留 50好友可见 60关注可见 70保留 80保留 90公开")
@ColumnDefault("50")
@Column(name = "visibility", nullable = false)
private Byte visibility;
@Comment("是否置顶")
@ColumnDefault("0")
@Column(name = "is_top", nullable = false)
private Boolean isTop = false;
@Comment("是否精华")
@ColumnDefault("0")
@Column(name = "is_essence", nullable = false)
private Boolean isEssence = false;
@Comment("是否锁定")
@ColumnDefault("0")
@Column(name = "is_lock", nullable = false)
private Boolean isLock = false;
@Comment("最新回复时间")
@Column(name = "latest_replied_on")
private Long latestRepliedOn = 0L;
@Comment("参与的主题")
@Column(name = "tags")
private String tags;
@Comment("附件价格(分)")
@ColumnDefault("0")
@Column(name = "attachment_price", nullable = false)
private Long attachmentPrice = 0L;
@Comment("IP地址")
@Column(name = "ip", length = 15)
private String ip;
@Comment("IP城市地址")
@Column(name = "ip_loc", length = 64)
private String ipLoc;
}

View File

@ -0,0 +1,30 @@
package com.lk.paopao.entity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Comment;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@Getter
@Setter
@Comment("冒泡/文章收藏")
@Entity
@Table(name = "p_post_collection", indexes = {
@Index(name = "idx_post_collection_post_id", columnList = "post_id"),
@Index(name = "idx_post_collection_user_id", columnList = "user_id")
})
@EntityListeners(AuditingEntityListener.class)
public class PostCollection extends BaseAuditingEntity{
@Comment("POST ID")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id", nullable = false)
private Post post;
@Comment("用户ID")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private User user;
}

View File

@ -0,0 +1,41 @@
package com.lk.paopao.entity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.Comment;
@Getter
@Setter
@Comment("冒泡/动态/文章内容")
@Entity
@Table(name = "p_post_content", indexes = {
@Index(name = "idx_post_content_post_id", columnList = "post_id"),
@Index(name = "idx_post_content_user_id", columnList = "user_id")
})
public class PostContent extends BaseAuditingEntity{
@Comment("冒泡/动态/文章ID")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id", nullable = false)
private Post post;
@Comment("用户ID")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private User user;
@Comment("内容")
@Column(name = "content", nullable = false, length = 4000)
private String content;
@Comment("类型1标题2文字段落3图片地址4视频地址5语音地址6链接地址7附件资源8收费资源")
@ColumnDefault("2")
@Column(name = "type", nullable = false)
private Byte type = 2;
@Comment("排序,越小越靠前")
@ColumnDefault("100")
@Column(name = "sort", nullable = false)
private Integer sort =100;
}

View File

@ -0,0 +1,29 @@
package com.lk.paopao.entity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Comment;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@Getter
@Setter
@Comment("冒泡/文章点赞")
@Entity
@Table(name = "p_post_star", indexes = {
@Index(name = "idx_post_star_post_id", columnList = "post_id"),
@Index(name = "idx_post_star_user_id", columnList = "user_id")
})
@EntityListeners(AuditingEntityListener.class)
public class PostStar extends BaseAuditingEntity{
@Comment("POST ID")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id", nullable = false)
private Post post;
@Comment("用户ID")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private User user;
}

View File

@ -0,0 +1,37 @@
package com.lk.paopao.entity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.Comment;
@Getter
@Setter
@Comment("标签")
@Entity
@Table(name = "p_tag", indexes = {
@Index(name = "idx_tag_user_id", columnList = "user_id"),
@Index(name = "idx_tag_quote_num", columnList = "quote_num")
}, uniqueConstraints = {
@UniqueConstraint(name = "idx_tag_tag", columnNames = {"tag"})
})
public class Tag extends BaseAuditingEntity{
@Version
private Long version;
@Comment("创建者ID")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private User user;
@Comment("标签名")
@Column(name = "tag", nullable = false)
private String tag;
@Comment("引用数")
@ColumnDefault("0")
@Column(name = "quote_num", nullable = false)
private Long quoteNum = 0L;
}

View File

@ -0,0 +1,15 @@
package com.lk.paopao.mapper;
import com.lk.paopao.dto.CommentContentDto;
import com.lk.paopao.entity.CommentContent;
import org.mapstruct.*;
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
public interface CommentContentMapper {
CommentContent toEntity(CommentContentDto commentContentDto);
CommentContentDto toDto(CommentContent commentContent);
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
CommentContent partialUpdate(CommentContentDto commentContentDto, @MappingTarget CommentContent commentContent);
}

View File

@ -0,0 +1,20 @@
package com.lk.paopao.mapper;
import com.lk.paopao.dto.CommentDto;
import com.lk.paopao.entity.Comment;
import org.mapstruct.*;
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
public interface CommentMapper {
Comment toEntity(CommentDto commentDto);
@AfterMapping
default void linkContents(@MappingTarget Comment comment) {
comment.getContents().forEach(content -> content.setComment(comment));
}
CommentDto toDto(Comment comment);
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
Comment partialUpdate(CommentDto commentDto, @MappingTarget Comment comment);
}

View File

@ -0,0 +1,15 @@
package com.lk.paopao.mapper;
import com.lk.paopao.dto.CommentReplyDto;
import com.lk.paopao.entity.CommentReply;
import org.mapstruct.*;
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
public interface CommentReplyMapper {
CommentReply toEntity(CommentReplyDto commentReplyDto);
CommentReplyDto toDto(CommentReply commentReply);
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
CommentReply partialUpdate(CommentReplyDto commentReplyDto, @MappingTarget CommentReply commentReply);
}

View File

@ -0,0 +1,15 @@
package com.lk.paopao.mapper;
import com.lk.paopao.dto.PostCollectionDto;
import com.lk.paopao.entity.PostCollection;
import org.mapstruct.*;
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
public interface PostCollectionMapper {
PostCollection toEntity(PostCollectionDto postCollectionDto);
PostCollectionDto toDto(PostCollection postCollection);
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
PostCollection partialUpdate(PostCollectionDto postCollectionDto, @MappingTarget PostCollection postCollection);
}

View File

@ -0,0 +1,15 @@
package com.lk.paopao.mapper;
import com.lk.paopao.entity.PostContent;
import com.lk.paopao.dto.PostContentDto;
import org.mapstruct.*;
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
public interface PostContentMapper {
PostContent toEntity(PostContentDto postContentDto);
PostContentDto toDto(PostContent postContent);
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
PostContent partialUpdate(PostContentDto postContentDto, @MappingTarget PostContent postContent);
}

View File

@ -0,0 +1,15 @@
package com.lk.paopao.mapper;
import com.lk.paopao.entity.Post;
import com.lk.paopao.dto.PostDto;
import org.mapstruct.*;
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
public interface PostMapper {
Post toEntity(PostDto postDto);
PostDto toDto(Post post);
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
Post partialUpdate(PostDto postDto, @MappingTarget Post post);
}

View File

@ -0,0 +1,15 @@
package com.lk.paopao.mapper;
import com.lk.paopao.dto.PostStarDto;
import com.lk.paopao.entity.PostStar;
import org.mapstruct.*;
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
public interface PostStarMapper {
PostStar toEntity(PostStarDto postStarDto);
PostStarDto toDto(PostStar postStar);
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
PostStar partialUpdate(PostStarDto postStarDto, @MappingTarget PostStar postStar);
}

View File

@ -0,0 +1,17 @@
package com.lk.paopao.mapper;
import com.lk.paopao.entity.Tag;
import com.lk.paopao.dto.TagDto;
import org.mapstruct.*;
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE, componentModel = MappingConstants.ComponentModel.SPRING)
public interface TagMapper {
Tag toEntity(TagDto tagDto);
@Mapping(source = "user.id", target = "userId")
@Mapping(source = "user", target = "user")
TagDto toDto(Tag tag);
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
Tag partialUpdate(TagDto tagDto, @MappingTarget Tag tag);
}

View File

@ -0,0 +1,7 @@
package com.lk.paopao.repository;
import com.lk.paopao.entity.CommentContent;
import org.springframework.data.jpa.repository.JpaRepository;
public interface CommentContentRepository extends JpaRepository<CommentContent, Long> {
}

View File

@ -0,0 +1,7 @@
package com.lk.paopao.repository;
import com.lk.paopao.entity.CommentReply;
import org.springframework.data.jpa.repository.JpaRepository;
public interface CommentReplyRepository extends JpaRepository<CommentReply, Long> {
}

View File

@ -0,0 +1,7 @@
package com.lk.paopao.repository;
import com.lk.paopao.entity.Comment;
import org.springframework.data.jpa.repository.JpaRepository;
public interface CommentRepository extends JpaRepository<Comment, Long> {
}

View File

@ -0,0 +1,7 @@
package com.lk.paopao.repository;
import com.lk.paopao.entity.PostCollection;
import org.springframework.data.jpa.repository.JpaRepository;
public interface PostCollectionRepository extends JpaRepository<PostCollection, Long> {
}

View File

@ -0,0 +1,7 @@
package com.lk.paopao.repository;
import com.lk.paopao.entity.PostContent;
import org.springframework.data.jpa.repository.JpaRepository;
public interface PostContentRepository extends JpaRepository<PostContent, Long> {
}

View File

@ -0,0 +1,7 @@
package com.lk.paopao.repository;
import com.lk.paopao.entity.Post;
import org.springframework.data.jpa.repository.JpaRepository;
public interface PostRepository extends JpaRepository<Post, Long> {
}

View File

@ -0,0 +1,7 @@
package com.lk.paopao.repository;
import com.lk.paopao.entity.PostStar;
import org.springframework.data.jpa.repository.JpaRepository;
public interface PostStarRepository extends JpaRepository<PostStar, Long> {
}

View File

@ -0,0 +1,19 @@
package com.lk.paopao.repository;
import com.lk.paopao.entity.Tag;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
import java.util.Optional;
public interface TagRepository extends JpaRepository<Tag, Long> {
@Query("SELECT t.tag FROM Tag t WHERE t.tag LIKE CONCAT('%', :key, '%') ORDER BY t.tag ASC limit 20")
List<String> findByTagContainingOrderByTagAsc(@Param("key") String key);
Optional<Tag> findByTag(String tag);
}

View File

@ -2,9 +2,17 @@ package com.lk.paopao.repository;
import com.lk.paopao.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
import java.util.Optional;
public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByUsername(String username);
// 或者使用@Query注解进行JPQL或SQL查询如果声明式方法命名无法满足复杂需求
@Query("SELECT u.username FROM User u WHERE u.username LIKE CONCAT('%', :key, '%') ORDER BY u.username ASC limit 20")
List<String> findByUsernameContainingOrderByUsernameAsc(@Param("key") String key);
}

View File

@ -25,7 +25,7 @@ spring:
defer-datasource-initialization: true
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: update
ddl-auto: create-drop
# 可选值create-drop,create,update,none. create-drop每次启动项目都会删除表然后重新创建表适合开发环境create每次启动项目都会创建表适合开发环境update每次启动项目都会更新表适合开发环境none不执行任何操作适合生产环境。
properties:
hibernate:
@ -49,6 +49,8 @@ app:
methods: ["GET"]
- path: "/v3/**"
methods: [ "GET" ]
- path: "/h2/**"
methods: [ "GET","PUT","POST" ]
- path: "/v1/auth/**"
methods: [ "GET","PUT","POST"]
- path: "/upload/**"