mirror of https://github.com/halo-dev/halo
🎨 代码优化
parent
58e91d6e14
commit
7ffbc93ea5
|
@ -5,6 +5,7 @@ import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cache.annotation.EnableCaching;
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
|
@ -17,6 +18,7 @@ import org.springframework.context.ApplicationContext;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableCaching
|
@EnableCaching
|
||||||
|
@EnableJpaAuditing
|
||||||
public class Application {
|
public class Application {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ApplicationContext context = SpringApplication.run(Application.class, args);
|
ApplicationContext context = SpringApplication.run(Application.class, args);
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
package cc.ryanc.halo.model.domain;
|
package cc.ryanc.halo.model.domain;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.springframework.data.annotation.CreatedDate;
|
||||||
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.*;
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
@ -20,6 +19,7 @@ import java.util.Date;
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "halo_attachment")
|
@Table(name = "halo_attachment")
|
||||||
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
public class Attachment implements Serializable {
|
public class Attachment implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 3060117944880138064L;
|
private static final long serialVersionUID = 3060117944880138064L;
|
||||||
|
@ -59,6 +59,7 @@ public class Attachment implements Serializable {
|
||||||
/**
|
/**
|
||||||
* 上传时间
|
* 上传时间
|
||||||
*/
|
*/
|
||||||
|
@CreatedDate
|
||||||
private Date attachCreated;
|
private Date attachCreated;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,6 +2,8 @@ package cc.ryanc.halo.model.domain;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.springframework.data.annotation.CreatedDate;
|
||||||
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.Email;
|
import javax.validation.constraints.Email;
|
||||||
|
@ -21,6 +23,7 @@ import java.util.List;
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "halo_comment")
|
@Table(name = "halo_comment")
|
||||||
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
public class Comment implements Serializable {
|
public class Comment implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -6639021627094260505L;
|
private static final long serialVersionUID = -6639021627094260505L;
|
||||||
|
@ -72,6 +75,7 @@ public class Comment implements Serializable {
|
||||||
/**
|
/**
|
||||||
* 评论时间
|
* 评论时间
|
||||||
*/
|
*/
|
||||||
|
@CreatedDate
|
||||||
private Date commentDate;
|
private Date commentDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
package cc.ryanc.halo.model.domain;
|
package cc.ryanc.halo.model.domain;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.springframework.data.annotation.CreatedDate;
|
||||||
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.*;
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
@ -20,6 +19,7 @@ import java.util.Date;
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "halo_logs")
|
@Table(name = "halo_logs")
|
||||||
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
public class Logs implements Serializable {
|
public class Logs implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -2571815432301283171L;
|
private static final long serialVersionUID = -2571815432301283171L;
|
||||||
|
@ -49,6 +49,7 @@ public class Logs implements Serializable {
|
||||||
/**
|
/**
|
||||||
* 产生的时间
|
* 产生的时间
|
||||||
*/
|
*/
|
||||||
|
@CreatedDate
|
||||||
private Date logCreated;
|
private Date logCreated;
|
||||||
|
|
||||||
public Logs() {
|
public Logs() {
|
||||||
|
|
|
@ -2,6 +2,9 @@ package cc.ryanc.halo.model.domain;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.springframework.data.annotation.CreatedDate;
|
||||||
|
import org.springframework.data.annotation.LastModifiedDate;
|
||||||
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@ -20,6 +23,7 @@ import java.util.List;
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "halo_post")
|
@Table(name = "halo_post")
|
||||||
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
public class Post implements Serializable {
|
public class Post implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -6019684584665869629L;
|
private static final long serialVersionUID = -6019684584665869629L;
|
||||||
|
@ -105,11 +109,13 @@ public class Post implements Serializable {
|
||||||
/**
|
/**
|
||||||
* 发表日期
|
* 发表日期
|
||||||
*/
|
*/
|
||||||
|
@CreatedDate
|
||||||
private Date postDate;
|
private Date postDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 最后一次更新时间
|
* 最后一次更新时间
|
||||||
*/
|
*/
|
||||||
|
@LastModifiedDate
|
||||||
private Date postUpdate;
|
private Date postUpdate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -39,7 +39,6 @@ public class LogsServiceImpl implements LogsService {
|
||||||
final Logs logs = new Logs();
|
final Logs logs = new Logs();
|
||||||
logs.setLogTitle(logTitle);
|
logs.setLogTitle(logTitle);
|
||||||
logs.setLogContent(logContent);
|
logs.setLogContent(logContent);
|
||||||
logs.setLogCreated(new Date());
|
|
||||||
logs.setLogIp(ServletUtil.getClientIP(request));
|
logs.setLogIp(ServletUtil.getClientIP(request));
|
||||||
logsRepository.save(logs);
|
logsRepository.save(logs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,6 @@ public class PostServiceImpl implements PostService {
|
||||||
} else {
|
} else {
|
||||||
post.setPostSummary(summaryText);
|
post.setPostSummary(summaryText);
|
||||||
}
|
}
|
||||||
post.setPostUpdate(DateUtil.date());
|
|
||||||
return postRepository.save(post);
|
return postRepository.save(post);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,6 @@ public class AttachmentController {
|
||||||
attachment.setAttachSmallPath(resultMap.get("smallPath"));
|
attachment.setAttachSmallPath(resultMap.get("smallPath"));
|
||||||
attachment.setAttachType(file.getContentType());
|
attachment.setAttachType(file.getContentType());
|
||||||
attachment.setAttachSuffix(resultMap.get("suffix"));
|
attachment.setAttachSuffix(resultMap.get("suffix"));
|
||||||
attachment.setAttachCreated(DateUtil.date());
|
|
||||||
attachment.setAttachSize(resultMap.get("size"));
|
attachment.setAttachSize(resultMap.get("size"));
|
||||||
attachment.setAttachWh(resultMap.get("wh"));
|
attachment.setAttachWh(resultMap.get("wh"));
|
||||||
attachment.setAttachLocation(resultMap.get("location"));
|
attachment.setAttachLocation(resultMap.get("location"));
|
||||||
|
|
|
@ -182,7 +182,6 @@ public class CommentController extends BaseController {
|
||||||
comment.setCommentAuthorUrl(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
comment.setCommentAuthorUrl(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
||||||
comment.setCommentAuthorIp(ServletUtil.getClientIP(request));
|
comment.setCommentAuthorIp(ServletUtil.getClientIP(request));
|
||||||
comment.setCommentAuthorAvatarMd5(SecureUtil.md5(user.getUserEmail()));
|
comment.setCommentAuthorAvatarMd5(SecureUtil.md5(user.getUserEmail()));
|
||||||
comment.setCommentDate(DateUtil.date());
|
|
||||||
|
|
||||||
final StrBuilder buildContent = new StrBuilder("<a href='#comment-id-");
|
final StrBuilder buildContent = new StrBuilder("<a href='#comment-id-");
|
||||||
buildContent.append(lastComment.getCommentId());
|
buildContent.append(lastComment.getCommentId());
|
||||||
|
|
|
@ -261,10 +261,7 @@ public class PageController {
|
||||||
}
|
}
|
||||||
post.setPostViews(oldPost.getPostViews());
|
post.setPostViews(oldPost.getPostViews());
|
||||||
msg = localeMessageUtil.getMessage("code.admin.common.update-success");
|
msg = localeMessageUtil.getMessage("code.admin.common.update-success");
|
||||||
} else {
|
|
||||||
post.setPostDate(DateUtil.date());
|
|
||||||
}
|
}
|
||||||
post.setPostUpdate(DateUtil.date());
|
|
||||||
post.setPostContent(MarkdownUtils.renderMarkdown(post.getPostContentMd()));
|
post.setPostContent(MarkdownUtils.renderMarkdown(post.getPostContentMd()));
|
||||||
//当没有选择文章缩略图的时候,自动分配一张内置的缩略图
|
//当没有选择文章缩略图的时候,自动分配一张内置的缩略图
|
||||||
if (StrUtil.equals(post.getPostThumbnail(), BlogPropertiesEnum.DEFAULT_THUMBNAIL.getProp())) {
|
if (StrUtil.equals(post.getPostThumbnail(), BlogPropertiesEnum.DEFAULT_THUMBNAIL.getProp())) {
|
||||||
|
|
|
@ -183,7 +183,6 @@ public class PostController extends BaseController {
|
||||||
final User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
final User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||||
try {
|
try {
|
||||||
post.setPostContent(MarkdownUtils.renderMarkdown(post.getPostContentMd()));
|
post.setPostContent(MarkdownUtils.renderMarkdown(post.getPostContentMd()));
|
||||||
post.setPostDate(DateUtil.date());
|
|
||||||
post.setUser(user);
|
post.setUser(user);
|
||||||
post = postService.buildCategoriesAndTags(post, cateList, tagList);
|
post = postService.buildCategoriesAndTags(post, cateList, tagList);
|
||||||
post.setPostUrl(urlFilter(post.getPostUrl()));
|
post.setPostUrl(urlFilter(post.getPostUrl()));
|
||||||
|
|
|
@ -137,7 +137,6 @@ public class InstallController {
|
||||||
post.setPostContent(MarkdownUtils.renderMarkdown(post.getPostContentMd()));
|
post.setPostContent(MarkdownUtils.renderMarkdown(post.getPostContentMd()));
|
||||||
post.setPostSummary("欢迎使用Halo进行创作,删除这篇文章后赶紧开始吧。");
|
post.setPostSummary("欢迎使用Halo进行创作,删除这篇文章后赶紧开始吧。");
|
||||||
post.setPostStatus(0);
|
post.setPostStatus(0);
|
||||||
post.setPostDate(DateUtil.date());
|
|
||||||
post.setPostUrl("hello-halo");
|
post.setPostUrl("hello-halo");
|
||||||
post.setUser(user);
|
post.setUser(user);
|
||||||
post.setCategories(categories);
|
post.setCategories(categories);
|
||||||
|
@ -152,7 +151,6 @@ public class InstallController {
|
||||||
comment.setCommentAuthorUrl("https://ryanc.cc");
|
comment.setCommentAuthorUrl("https://ryanc.cc");
|
||||||
comment.setCommentAuthorIp("127.0.0.1");
|
comment.setCommentAuthorIp("127.0.0.1");
|
||||||
comment.setCommentAuthorAvatarMd5(SecureUtil.md5("i@ryanc.cc"));
|
comment.setCommentAuthorAvatarMd5(SecureUtil.md5("i@ryanc.cc"));
|
||||||
comment.setCommentDate(DateUtil.date());
|
|
||||||
comment.setCommentContent("欢迎,欢迎!");
|
comment.setCommentContent("欢迎,欢迎!");
|
||||||
comment.setCommentStatus(0);
|
comment.setCommentStatus(0);
|
||||||
comment.setCommentAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36");
|
comment.setCommentAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36");
|
||||||
|
|
|
@ -86,7 +86,6 @@ public class FrontCommentController {
|
||||||
post = postService.findByPostId(post.getPostId()).orElse(new Post());
|
post = postService.findByPostId(post.getPostId()).orElse(new Post());
|
||||||
comment.setCommentAuthorEmail(HtmlUtil.escape(comment.getCommentAuthorEmail()).toLowerCase());
|
comment.setCommentAuthorEmail(HtmlUtil.escape(comment.getCommentAuthorEmail()).toLowerCase());
|
||||||
comment.setPost(post);
|
comment.setPost(post);
|
||||||
comment.setCommentDate(DateUtil.date());
|
|
||||||
comment.setCommentAuthorIp(ServletUtil.getClientIP(request));
|
comment.setCommentAuthorIp(ServletUtil.getClientIP(request));
|
||||||
comment.setIsAdmin(0);
|
comment.setIsAdmin(0);
|
||||||
comment.setCommentAuthor(HtmlUtil.escape(comment.getCommentAuthor()));
|
comment.setCommentAuthor(HtmlUtil.escape(comment.getCommentAuthor()));
|
||||||
|
|
Loading…
Reference in New Issue