重构Article模块 新增Message模块 优化安全配置
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
package com.qf.myafterprojecy.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "article")
|
||||
@@ -11,18 +12,35 @@ public class Article {
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "articleid")
|
||||
private Integer articleid;
|
||||
|
||||
@NotBlank(message = "标题不能为空")
|
||||
@Column(name = "title")
|
||||
private String title;
|
||||
@Column(name = "content")
|
||||
|
||||
@NotBlank(message = "内容不能为空")
|
||||
@Column(name = "content", columnDefinition = "TEXT")
|
||||
private String content;
|
||||
|
||||
@NotNull(message = "类别id不能为空")
|
||||
@Column(name = "typeid")
|
||||
private Integer typeid;
|
||||
|
||||
@Column(name = "img")
|
||||
private String img;
|
||||
@Column(name = "typeid")
|
||||
private int typeid;
|
||||
@Column(name = "published_at")
|
||||
private String publisher_at;
|
||||
|
||||
@Column(name = "created_at")
|
||||
private String created_at;
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Column(name = "updated_at")
|
||||
private LocalDateTime updatedAt;
|
||||
@Column(name = "view_count")
|
||||
private Integer viewCount;
|
||||
|
||||
@Column(name = "status")
|
||||
private Integer status; // 0-草稿,1-已发布,2-已删除
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
|
||||
public Integer getArticleid() {
|
||||
return articleid;
|
||||
@@ -48,6 +66,38 @@ public class Article {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public Integer getTypeid() {
|
||||
return typeid;
|
||||
}
|
||||
|
||||
public void setTypeid(Integer typeid) {
|
||||
this.typeid = typeid;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(LocalDateTime createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public LocalDateTime getUpdatedAt() {
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
public void setUpdatedAt(LocalDateTime updatedAt) {
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getImg() {
|
||||
return img;
|
||||
}
|
||||
@@ -56,40 +106,11 @@ public class Article {
|
||||
this.img = img;
|
||||
}
|
||||
|
||||
public int getTypeid() {
|
||||
return typeid;
|
||||
public Integer getViewCount() {
|
||||
return viewCount;
|
||||
}
|
||||
|
||||
public void setTypeid(int typeid) {
|
||||
this.typeid = typeid;
|
||||
}
|
||||
|
||||
public String getPublisher_at() {
|
||||
return publisher_at;
|
||||
}
|
||||
|
||||
public void setPublisher_at(String publisher_at) {
|
||||
this.publisher_at = publisher_at;
|
||||
}
|
||||
|
||||
public String getCreated_at() {
|
||||
return created_at;
|
||||
}
|
||||
|
||||
public void setCreated_at(String created_at) {
|
||||
this.created_at = created_at;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Article{" +
|
||||
"articleid=" + articleid +
|
||||
", title='" + title + '\'' +
|
||||
", content='" + content + '\'' +
|
||||
", img='" + img + '\'' +
|
||||
", typeid=" + typeid +
|
||||
", publisher_at='" + publisher_at + '\'' +
|
||||
", created_at='" + created_at + '\'' +
|
||||
'}';
|
||||
public void setViewCount(Integer viewCount) {
|
||||
this.viewCount = viewCount;
|
||||
}
|
||||
}
|
||||
|
||||
83
src/main/java/com/qf/myafterprojecy/pojo/Message.java
Normal file
83
src/main/java/com/qf/myafterprojecy/pojo/Message.java
Normal file
@@ -0,0 +1,83 @@
|
||||
package com.qf.myafterprojecy.pojo;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
@Table(name = "message")
|
||||
public class Message {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer messageid;
|
||||
|
||||
private String nickname;
|
||||
|
||||
private String email;
|
||||
|
||||
@Column(columnDefinition = "text")
|
||||
private String content;
|
||||
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date createdAt;
|
||||
|
||||
private Integer parentid;
|
||||
|
||||
private Integer articleid;
|
||||
|
||||
|
||||
public Integer getMessageid() {
|
||||
return messageid;
|
||||
}
|
||||
|
||||
public void setMessageid(Integer messageid) {
|
||||
this.messageid = messageid;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Integer getParentid() {
|
||||
return parentid;
|
||||
}
|
||||
|
||||
public void setParentid(Integer parentid) {
|
||||
this.parentid = parentid;
|
||||
}
|
||||
|
||||
public Integer getArticleid() {
|
||||
return articleid;
|
||||
}
|
||||
|
||||
public void setArticleid(Integer articleid) {
|
||||
this.articleid = articleid;
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,11 @@ package com.qf.myafterprojecy.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
@Data
|
||||
public class ResponseMessage<T> {
|
||||
private Integer code;
|
||||
private String message;
|
||||
private boolean success;
|
||||
private T data;
|
||||
public ResponseMessage(Integer code, String message, T data) {
|
||||
this.code = code;
|
||||
@@ -13,6 +14,14 @@ public class ResponseMessage<T> {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
@@ -36,18 +45,54 @@ public class ResponseMessage<T> {
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
public ResponseMessage(Integer code, String message, T data, boolean success) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.data = data;
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
// 接口请求成功
|
||||
public static <T> ResponseMessage<T> success(T data ,String message ,boolean success) {
|
||||
return new ResponseMessage(HttpStatus.OK.value(), message, data ,success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个表示操作失败的响应消息
|
||||
* @param message 失败原因的描述信息
|
||||
* @return 返回一个包含错误状态码和错误信息的ResponseMessage对象
|
||||
*/
|
||||
public static <T> ResponseMessage<T> failure(String message) {
|
||||
return new ResponseMessage<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), message, null, false);
|
||||
}
|
||||
|
||||
|
||||
public static <T> ResponseMessage<T> success(T data) {
|
||||
return new ResponseMessage(HttpStatus.OK.value(), "success", data);
|
||||
return new ResponseMessage<>(HttpStatus.OK.value(), "操作成功", data, true);
|
||||
}
|
||||
|
||||
public static <T> ResponseMessage<T> Delete(Boolean delete) {
|
||||
return new ResponseMessage(HttpStatus.OK.value(), "delete", delete);
|
||||
public static <T> ResponseMessage<T> success(T data, String message) {
|
||||
return new ResponseMessage<>(HttpStatus.OK.value(), message, data, true);
|
||||
}
|
||||
|
||||
public static <T> ResponseMessage<T> Save(Boolean save) {
|
||||
return new ResponseMessage(HttpStatus.OK.value(), "save", save);
|
||||
public static <T> ResponseMessage<T> error(String message) {
|
||||
return new ResponseMessage<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), message, null, false);
|
||||
}
|
||||
|
||||
public static <T> ResponseMessage<T> error(Integer code, String message) {
|
||||
return new ResponseMessage<>(code, message, null, false);
|
||||
}
|
||||
|
||||
public static <T> ResponseMessage<T> Save(boolean success) {
|
||||
return success ?
|
||||
new ResponseMessage<>(HttpStatus.OK.value(), "保存成功", null, true) :
|
||||
new ResponseMessage<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), "保存失败", null, false);
|
||||
}
|
||||
|
||||
public static <T> ResponseMessage<T> Delete(boolean success) {
|
||||
return success ?
|
||||
new ResponseMessage<>(HttpStatus.OK.value(), "删除成功", null, true) :
|
||||
new ResponseMessage<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), "删除失败", null, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,21 +1,32 @@
|
||||
package com.qf.myafterprojecy.pojo.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Getter
|
||||
public class ArticleDto {
|
||||
private Integer articleid;
|
||||
private String title;
|
||||
private String content;
|
||||
private String img;
|
||||
private Integer typeid;
|
||||
private String publisher_at;
|
||||
private String created_at;
|
||||
private Integer id;
|
||||
|
||||
public Integer getArticleid() {
|
||||
return articleid;
|
||||
@NotBlank(message = "标题不能为空")
|
||||
private String title;
|
||||
|
||||
@NotBlank(message = "内容不能为空")
|
||||
private String content;
|
||||
|
||||
private String img;
|
||||
|
||||
private Integer status;
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setArticleid(Integer articleid) {
|
||||
this.articleid = articleid;
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
@@ -34,6 +45,14 @@ public class ArticleDto {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getImg() {
|
||||
return img;
|
||||
}
|
||||
@@ -41,41 +60,4 @@ public class ArticleDto {
|
||||
public void setImg(String img) {
|
||||
this.img = img;
|
||||
}
|
||||
|
||||
public Integer getTypeid() {
|
||||
return typeid;
|
||||
}
|
||||
|
||||
public void setTypeid(Integer typeid) {
|
||||
this.typeid = typeid;
|
||||
}
|
||||
|
||||
public String getPublisher_at() {
|
||||
return publisher_at;
|
||||
}
|
||||
|
||||
public void setPublisher_at(String publisher_at) {
|
||||
this.publisher_at = publisher_at;
|
||||
}
|
||||
|
||||
public String getCreated_at() {
|
||||
return created_at;
|
||||
}
|
||||
|
||||
public void setCreated_at(String created_at) {
|
||||
this.created_at = created_at;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ArticleDto{" +
|
||||
"articleid=" + articleid +
|
||||
", title='" + title + '\'' +
|
||||
", content='" + content + '\'' +
|
||||
", img='" + img + '\'' +
|
||||
", typeid=" + typeid +
|
||||
", publisher_at='" + publisher_at + '\'' +
|
||||
", created_at='" + created_at + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
77
src/main/java/com/qf/myafterprojecy/pojo/dto/MessageDto.java
Normal file
77
src/main/java/com/qf/myafterprojecy/pojo/dto/MessageDto.java
Normal file
@@ -0,0 +1,77 @@
|
||||
package com.qf.myafterprojecy.pojo.dto;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
|
||||
public class MessageDto {
|
||||
private Integer messageid;
|
||||
|
||||
private String nickname;
|
||||
|
||||
private String email;
|
||||
|
||||
private String content;
|
||||
|
||||
private Date createdAt;
|
||||
|
||||
private Integer parentid;
|
||||
|
||||
private Integer articleid;
|
||||
|
||||
|
||||
public Integer getMessageid() {
|
||||
return messageid;
|
||||
}
|
||||
|
||||
public void setMessageid(Integer messageid) {
|
||||
this.messageid = messageid;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Integer getParentid() {
|
||||
return parentid;
|
||||
}
|
||||
|
||||
public void setParentid(Integer parentid) {
|
||||
this.parentid = parentid;
|
||||
}
|
||||
|
||||
public Integer getArticleid() {
|
||||
return articleid;
|
||||
}
|
||||
|
||||
public void setArticleid(Integer articleid) {
|
||||
this.articleid = articleid;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user