-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
323 additions
and
127 deletions.
There are no files selected for viewing
28 changes: 0 additions & 28 deletions
28
src/main/java/com/chinasoft/forum/controller/CommentController.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,7 +140,7 @@ public String Send(HttpServletRequest request) { | |
try { | ||
email.addTo(userEmail); | ||
email.setFrom("[email protected]", "聚集地论坛"); | ||
email.setAuthentication("[email protected]", "nlqqmczegpalbagd"); | ||
email.setAuthentication("[email protected]", "rkjhrvjftpizigbg"); | ||
email.setSubject("邮箱验证");//设置发送主题 | ||
String code = RandomCode(); | ||
email.setMsg("您正在注册聚集地论坛,您的验证码为: " + code + ",有效时间三分钟。 如非本人操作,请忽略本邮件。");//设置发送内容 | ||
|
107 changes: 107 additions & 0 deletions
107
src/main/java/com/chinasoft/forum/controller/PostController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package com.chinasoft.forum.controller; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.chinasoft.forum.dal.entity.Comment; | ||
import com.chinasoft.forum.dal.entity.Post; | ||
import com.chinasoft.forum.dal.entity.User; | ||
import com.chinasoft.forum.service.CommentService; | ||
import com.chinasoft.forum.service.PostService; | ||
import com.chinasoft.forum.service.UserService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.ModelMap; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@Controller | ||
public class PostController { | ||
|
||
@Autowired | ||
private CommentService commentService; | ||
|
||
@Autowired | ||
private UserService userService; | ||
|
||
@Autowired | ||
private PostService postService; | ||
|
||
@RequestMapping("postDetail") | ||
public String toPostDetail(ModelMap modelMap){ | ||
Integer postId=1; | ||
Post postDetail=postService.getDetail(postId); | ||
modelMap.put("postDetail",postDetail); | ||
List<Comment> parentComments=commentService.findAllParentComment(postId); | ||
User user; | ||
for(int i=0;i<parentComments.size();i++){ | ||
user = userService.userCoookie(parentComments.get(i).getUserEmail()); | ||
parentComments.get(i).setUserNickName(user.getNickName()); | ||
} | ||
if(parentComments.size()!=0) { | ||
modelMap.put("parentComments", parentComments); | ||
modelMap.put("parentCommentsNumber", parentComments.size()); | ||
} | ||
return "postDetail"; | ||
} | ||
|
||
@RequestMapping(value = "writeComment",method = RequestMethod.POST) | ||
@ResponseBody | ||
public boolean writeComment(HttpServletRequest request){ | ||
User user=(User)request.getSession().getAttribute("User"); | ||
String userEmail=user.getUserEmail(); | ||
String nickName=user.getNickName(); | ||
String content=request.getParameter("commentContent"); | ||
Comment comment=new Comment(); | ||
comment.setUserEmail(userEmail); | ||
comment.setCommentTime(new Date()); | ||
comment.setContent(content); | ||
comment.setPostId(1); | ||
comment.setUserNickName(nickName); | ||
commentService.insert(comment); | ||
return true; | ||
} | ||
@RequestMapping("commentDetail") | ||
public String commentDetail(ModelMap modelMap){ | ||
Integer parentId=1; | ||
Integer postId=1; | ||
List<Comment> childrenComments=commentService.findAllChildComment(parentId,postId); | ||
User user; | ||
for(int i=0;i<childrenComments.size();i++){ | ||
user = userService.userCoookie(childrenComments.get(i).getUserEmail()); | ||
childrenComments.get(i).setUserNickName(user.getNickName()); | ||
user=userService.userCoookie(childrenComments.get(i).getRespondentUserEmail()); | ||
childrenComments.get(i).setRespondentUserNickName(user.getNickName()); | ||
} | ||
if(childrenComments.size()!=0) { | ||
modelMap.put("childrenComments", childrenComments); | ||
modelMap.put("childrenCommentsNumber", childrenComments.size()); | ||
} | ||
return "postDetail"; | ||
} | ||
|
||
@ResponseBody | ||
@RequestMapping(value = "writeAction", method = RequestMethod.POST) | ||
public String write(HttpServletRequest request){ | ||
try { | ||
Integer section_name = Integer.parseInt(request.getParameter("section_name")); //板块 | ||
String title = request.getParameter("title"); //标题 | ||
String content = request.getParameter("content"); //内容 | ||
Boolean commentable = Boolean.parseBoolean(request.getParameter("commentable")); //是否可评论 | ||
String summary = content.replaceAll("<([^>]*)>", ""); //摘要需要先把内容正则化,然后再次判断其长度; //取摘要 | ||
if(summary.length()>=20) | ||
summary=summary.substring(0,20); | ||
User user= (User)request.getSession().getAttribute("User"); | ||
String author_email=user.getUserEmail(); | ||
postService.writeContent(author_email, section_name, title, summary, content, commentable, "正常", new Date()); | ||
return JSON.toJSONString("发表成功!"); | ||
} catch (NumberFormatException e) { | ||
e.printStackTrace(); | ||
return JSON.toJSONString("发表失败!"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.chinasoft.forum.dal; | ||
|
||
import com.chinasoft.forum.dal.entity.Post; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface PostRepository extends JpaRepository<Post,String> { | ||
|
||
List<Post> findBySectionNameOrderByLastEditTimeDesc(String sectionName); | ||
|
||
List<Post> findBySectionNameOrderByStarNumberDesc(String sectionName); | ||
|
||
Post findByPostId(Integer id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/chinasoft/forum/service/PostService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.chinasoft.forum.service; | ||
|
||
import com.chinasoft.forum.dal.entity.Post; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
public interface PostService { | ||
void writeContent(String author_email, Integer section_name, String title, String summary, String content, boolean commentable, String post_status, Date lastEditTime); | ||
|
||
List<Post> getByEdiTime(String sectionName); | ||
|
||
List<Post> getByStarNumber(String sectionName); | ||
|
||
Post getDetail(Integer postId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/com/chinasoft/forum/service/impl/PostServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.chinasoft.forum.service.impl; | ||
|
||
import com.chinasoft.forum.dal.PostRepository; | ||
import com.chinasoft.forum.dal.entity.Post; | ||
import com.chinasoft.forum.service.PostService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@Service | ||
public class PostServiceImpl implements PostService { | ||
@Autowired | ||
private PostRepository postRepository; | ||
|
||
public List<Post> getByEdiTime(String sectionName){ | ||
List<Post> postList=postRepository.findBySectionNameOrderByLastEditTimeDesc(sectionName); | ||
return postList; | ||
} | ||
|
||
@Override | ||
public List<Post> getByStarNumber(String sectionName) { | ||
List<Post> postList=postRepository.findBySectionNameOrderByStarNumberDesc(sectionName); | ||
return postList; | ||
} | ||
|
||
@Override | ||
public Post getDetail(Integer postId) { | ||
return postRepository.findByPostId(postId); | ||
} | ||
|
||
@Override | ||
public void writeContent(String author_email, Integer section_name, String title, String summary, String content, boolean commentable, String post_status, Date lastEditTime) { | ||
Post post=new Post(); | ||
post.setAuthorEmail(author_email); | ||
post.setSectionName(section_name); | ||
post.setTitle(title); | ||
post.setSummary(summary); | ||
post.setContent(content); | ||
post.setFirstImg(content); | ||
post.setCommentable(commentable); | ||
post.setPostStatus(post_status); | ||
post.setLastEditTime(lastEditTime); | ||
postRepository.save(post); | ||
} | ||
} |
Oops, something went wrong.