mirror of https://github.com/halo-dev/halo
🎨 代码优化
parent
da6ffd600d
commit
2cc45c353c
5
pom.xml
5
pom.xml
|
@ -282,11 +282,6 @@
|
|||
<fork>true</fork>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
|||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -33,11 +34,13 @@ public class Category implements Serializable {
|
|||
/**
|
||||
* 分类名称
|
||||
*/
|
||||
@NotBlank(message = "分类名称不能为空")
|
||||
private String cateName;
|
||||
|
||||
/**
|
||||
* 分类路径
|
||||
*/
|
||||
@NotBlank(message = "分类路径不能为空")
|
||||
private String cateUrl;
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
|||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
@ -41,11 +43,13 @@ public class Comment implements Serializable {
|
|||
/**
|
||||
* 评论人
|
||||
*/
|
||||
@NotBlank(message = "评论用户名不能为空")
|
||||
private String commentAuthor;
|
||||
|
||||
/**
|
||||
* 评论人的邮箱
|
||||
*/
|
||||
@Email(message = "邮箱格式不正确")
|
||||
@JsonIgnore
|
||||
private String commentAuthorEmail;
|
||||
|
||||
|
@ -73,6 +77,7 @@ public class Comment implements Serializable {
|
|||
/**
|
||||
* 评论内容
|
||||
*/
|
||||
@NotBlank(message = "评论内容不能为空")
|
||||
@Lob
|
||||
private String commentContent;
|
||||
|
||||
|
|
|
@ -7,6 +7,8 @@ import javax.persistence.Entity;
|
|||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
@ -35,6 +37,7 @@ public class User implements Serializable {
|
|||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@NotBlank(message = "用户名不能为空")
|
||||
@JsonIgnore
|
||||
private String userName;
|
||||
|
||||
|
@ -52,6 +55,7 @@ public class User implements Serializable {
|
|||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@Email(message = "邮箱格式不正确")
|
||||
private String userEmail;
|
||||
|
||||
/**
|
||||
|
|
|
@ -41,6 +41,7 @@ public class CategoryController {
|
|||
*/
|
||||
@PostMapping(value = "/save")
|
||||
public String saveCategory(@ModelAttribute Category category) {
|
||||
|
||||
try {
|
||||
categoryService.saveByCategory(category);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -9,9 +9,12 @@ import freemarker.template.Configuration;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* @author : RYAN0UP
|
||||
|
@ -47,15 +50,16 @@ public class UserController {
|
|||
*/
|
||||
@PostMapping(value = "save")
|
||||
@ResponseBody
|
||||
public JsonResult saveProfile(@ModelAttribute User user, HttpSession session) {
|
||||
public JsonResult saveProfile(@Valid @ModelAttribute User user, BindingResult result, HttpSession session) {
|
||||
try {
|
||||
if (null != user) {
|
||||
if (result.hasErrors()) {
|
||||
for (ObjectError error : result.getAllErrors()) {
|
||||
return new JsonResult(ResultCode.FAIL.getCode(), error.getDefaultMessage());
|
||||
}
|
||||
}
|
||||
userService.saveByUser(user);
|
||||
configuration.setSharedVariable("user", userService.findUser());
|
||||
session.invalidate();
|
||||
} else {
|
||||
return new JsonResult(ResultCode.FAIL.getCode(), "修改失败!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("修改用户资料失败:{}", e.getMessage());
|
||||
return new JsonResult(ResultCode.FAIL.getCode(), "修改失败!");
|
||||
|
|
|
@ -24,9 +24,12 @@ import org.springframework.data.domain.Pageable;
|
|||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -95,14 +98,14 @@ public class FrontCommentController {
|
|||
*/
|
||||
@PostMapping(value = "/newComment")
|
||||
@ResponseBody
|
||||
public JsonResult newComment(@ModelAttribute("comment") Comment comment,
|
||||
public JsonResult newComment(@Valid @ModelAttribute("comment") Comment comment,
|
||||
BindingResult result,
|
||||
@ModelAttribute("post") Post post,
|
||||
HttpServletRequest request) {
|
||||
if (StringUtils.equals(StringUtils.trim(comment.getCommentAuthor()), "")) {
|
||||
return new JsonResult(ResultCode.FAIL.getCode(), "请正确输入昵称!");
|
||||
if (result.hasErrors()) {
|
||||
for (ObjectError error : result.getAllErrors()) {
|
||||
return new JsonResult(ResultCode.FAIL.getCode(), error.getDefaultMessage());
|
||||
}
|
||||
if (StringUtils.equals(StringUtils.trim(comment.getCommentContent()), "")) {
|
||||
return new JsonResult(ResultCode.FAIL.getCode(), "请正确输入评论内容!");
|
||||
}
|
||||
try {
|
||||
Comment lastComment = null;
|
||||
|
|
Loading…
Reference in New Issue