Merge pull request #1 from Chuyaoyuan/master

v1 merge
This commit is contained in:
2023-07-31 22:24:30 +08:00
committed by GitHub
25 changed files with 122 additions and 117 deletions
@@ -3,7 +3,6 @@ package com.yaoyuan.jiscuss.common;
import com.yaoyuan.jiscuss.entity.custom.PostCustom; import com.yaoyuan.jiscuss.entity.custom.PostCustom;
import lombok.Data; import lombok.Data;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@@ -18,8 +17,11 @@ import java.util.List;
@Data @Data
public class Node { public class Node {
/**
* Node
* 空方法
**/
public Node() { public Node() {
} }
private Integer id; private Integer id;
@@ -52,7 +54,10 @@ public class Node {
private Date createTime; private Date createTime;
//用户表相关 /**
* avatar
* 用户表相关
**/
private String avatar; private String avatar;
private String username; private String username;
@@ -116,7 +121,10 @@ public class Node {
return firstList; return firstList;
} }
//打印 /**
* 打印
* show
**/
public static void show(List<Node> list) { public static void show(List<Node> list) {
for (Node node : list) { for (Node node : list) {
System.out.println(node.getUserId() + " 用户回复了你:" + node.getContent()); System.out.println(node.getUserId() + " 用户回复了你:" + node.getContent());
@@ -14,16 +14,14 @@ import java.util.Map;
/** /**
* @author yaoyuan2.chu * @author yaoyuan2.chu
* @Title: * @Title: 工具类
* @Package com.yaoyuan.jiscuss.common * @Package com.yaoyuan.jiscuss.common
* @Description: * @Description: 通用工具类
* @date 2020/9/10 15:47 * @date 2020/9/10 15:47
*/ */
public class PostCommonUtil { public class PostCommonUtil {
public static List<PostCustom> getNewPostsObjMap(List<Map<String, Object>> posts) { public static List<PostCustom> getNewPostsObjMap(List<Map<String, Object>> posts) {
List<PostCustom> postCustomList = new ArrayList<>(); List<PostCustom> postCustomList = new ArrayList<>();
for (Map<String, Object> mapObj : posts) { for (Map<String, Object> mapObj : posts) {
PostCustom postCustom = new PostCustom(); PostCustom postCustom = new PostCustom();
@@ -72,6 +70,11 @@ public class PostCommonUtil {
return postCustomList; return postCustomList;
} }
/**
* 获取post
* @param postCustomList
* @return List<PostCustom>
*/
public static List<PostCustom> getNewPostsObjCustom(List<PostCustom> postCustomList) { public static List<PostCustom> getNewPostsObjCustom(List<PostCustom> postCustomList) {
List<PostCustom> mainList = new ArrayList<>(); List<PostCustom> mainList = new ArrayList<>();
Map<String, Object> postMap = new LinkedHashMap<>(); Map<String, Object> postMap = new LinkedHashMap<>();
@@ -101,17 +104,18 @@ public class PostCommonUtil {
mainListResult.add(mapObj); mainListResult.add(mapObj);
} }
} }
return mainListResult; return mainListResult;
} }
// Clob类型转换成String类型 /**
* Clob类型转换成String类型
* @param clob
* @return
*/
public static String clobToString(final Clob clob) { public static String clobToString(final Clob clob) {
if (clob == null) { if (clob == null) {
return null; return null;
} }
Reader is = null; Reader is = null;
try { try {
is = clob.getCharacterStream(); is = clob.getCharacterStream();
@@ -119,14 +123,12 @@ public class PostCommonUtil {
e.printStackTrace(); e.printStackTrace();
} }
BufferedReader br = new BufferedReader(is); BufferedReader br = new BufferedReader(is);
String str = null; String str = null;
try { try {
str = br.readLine(); // 读取第一行 str = br.readLine(); // 读取第一行
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
while (str != null) { // 如果没有到达流的末尾,则继续读取下一行 while (str != null) { // 如果没有到达流的末尾,则继续读取下一行
sb.append(str); sb.append(str);
@@ -136,9 +138,7 @@ public class PostCommonUtil {
e.printStackTrace(); e.printStackTrace();
} }
} }
String returnString = sb.toString(); String returnString = sb.toString();
return returnString; return returnString;
} }
} }
@@ -7,16 +7,19 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration @Configuration
public class MyMvcConfig implements WebMvcConfigurer { public class MyMvcConfig implements WebMvcConfigurer {
/*
* addResourceHandlers
* void
*/
@Override @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) { public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html") registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/"); .addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**") registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/"); .addResourceLocations("classpath:/META-INF/resources/webjars/");
registry.addResourceHandler("/static/**") registry.addResourceHandler("/static/**")
.addResourceLocations("classpath:/static/"); .addResourceLocations("classpath:/static/");
} }
} }
@@ -18,15 +18,16 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
* prePostEnabled :决定Spring Security的前注解是否可用 [@PreAuthorize,@PostAuthorize,..] * prePostEnabled :决定Spring Security的前注解是否可用 [@PreAuthorize,@PostAuthorize,..]
* secureEnabled : 决定是否Spring Security的保障注解 [@Secured] 是否可用 * secureEnabled : 决定是否Spring Security的保障注解 [@Secured] 是否可用
* jsr250Enabled :决定 JSR-250 annotations 注解[@RolesAllowed..] 是否可用. * jsr250Enabled :决定 JSR-250 annotations 注解[@RolesAllowed..] 是否可用.
* 开启 Spring Security 方法级安全注解 @EnableGlobalMethodSecurity
*/ */
@Configurable @Configurable
@EnableWebSecurity @EnableWebSecurity
//开启 Spring Security 方法级安全注解 @EnableGlobalMethodSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true) @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true, jsr250Enabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired @Autowired
private CustomAccessDeniedHandler customAccessDeniedHandler; private CustomAccessDeniedHandler customAccessDeniedHandler;
@Qualifier("userDetailServiceImpl") @Qualifier("userDetailServiceImpl")
@Autowired @Autowired
private UserDetailsService userDetailsService; private UserDetailsService userDetailsService;
@@ -92,7 +93,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
/** /**
* 密码加密算法 * 密码加密算法
*
* @return * @return
*/ */
@Bean @Bean
@@ -100,4 +100,5 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
return new BCryptPasswordEncoder(); return new BCryptPasswordEncoder();
} }
} }
@@ -9,25 +9,34 @@ import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
/** /**
* @author yaoyuan2.chu
* 后台系统控制器 * 后台系统控制器
*/ */
@Controller @Controller
public class AdminSystemController { public class AdminSystemController {
//后台登录 /**
* 后台登录
*/
//后台退出 /**
* 后台退出
*/
@RequestMapping("/admin/logout")
public String logout(@RequestParam(defaultValue = "discussion") String type, HttpServletRequest request, ModelMap map) {
return "admin/logout";
}
//后台设置管理 /**
* 后台设置管理
*/
/** /**
* 后台页面 * 后台页面
*
* @return * @return
*/ */
@RequestMapping("/admin/home") @RequestMapping("/admin/home")
public String user(@RequestParam(defaultValue = "discussion") String type, HttpServletRequest request, ModelMap map) { public String home(@RequestParam(defaultValue = "discussion") String type, HttpServletRequest request, ModelMap map) {
return "admin/home"; return "admin/home";
} }
} }
@@ -3,6 +3,7 @@ package com.yaoyuan.jiscuss.controller;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
/** /**
* @author yaoyuan2.chu
* 用户消息控制器 * 用户消息控制器
*/ */
@Controller @Controller
@@ -3,10 +3,13 @@ package com.yaoyuan.jiscuss.controller;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
/** /**
* @author yaoyuan2.chu
* 其他控制器——积分/权限等 * 其他控制器——积分/权限等
*/ */
@Controller @Controller
public class UserOtherController extends BaseController { public class UserOtherController extends BaseController {
//用户积分获取 /**
* 用户积分获取
*/
} }
@@ -35,7 +35,6 @@ public class UserPageController extends BaseController {
@Autowired @Autowired
private ITagsService tagsService; private ITagsService tagsService;
/** /**
* 用户页面 * 用户页面
* *
@@ -44,12 +43,15 @@ public class UserPageController extends BaseController {
@RequestMapping("/user") @RequestMapping("/user")
public String user(@RequestParam(defaultValue = "discussion") String type, HttpServletRequest request, ModelMap map) { public String user(@RequestParam(defaultValue = "discussion") String type, HttpServletRequest request, ModelMap map) {
// type 判断
if (type.equals("discussion")) { if (type.equals("discussion")) {
map.put("discussion", "active"); map.put("discussion", "active");
} }
if (type.equals("change")) { if (type.equals("change")) {
map.put("change", "active"); map.put("change", "active");
} }
if (type.equals("like")) { if (type.equals("like")) {
map.put("like", "active"); map.put("like", "active");
} }
@@ -59,6 +61,8 @@ public class UserPageController extends BaseController {
map.put("username", user.getUsername()); map.put("username", user.getUsername());
map.put("data", "Jiscuss 用户:" + user.getUsername()); map.put("data", "Jiscuss 用户:" + user.getUsername());
} }
return "user"; return "user";
} }
} }
@@ -32,6 +32,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
/** /**
* @author yaoyuan2.chu
* 主题帖子评论控制器 * 主题帖子评论控制器
*/ */
@Controller @Controller
@@ -55,10 +56,18 @@ public class UserPostController extends BaseController {
private IUsersService usersService; private IUsersService usersService;
//首页查看主题列表(各种条件筛选,最热最新标签等) /**
* 首页查看主题列表(各种条件筛选,最热最新标签等)
*/
//查看主题详情 /**
* 查看主题详情
* @param request
* @param map
* @param id
* @return
*/
@RequestMapping("/getdiscussionsbyid") @RequestMapping("/getdiscussionsbyid")
public String getDiscussionsById(HttpServletRequest request, ModelMap map, @RequestParam("id") Integer id) { public String getDiscussionsById(HttpServletRequest request, ModelMap map, @RequestParam("id") Integer id) {
logger.info(">>> getDiscussionsById{}", id); logger.info(">>> getDiscussionsById{}", id);
@@ -82,7 +91,6 @@ public class UserPostController extends BaseController {
newdd.setUsernameLast(lastUser.getUsername()); newdd.setUsernameLast(lastUser.getUsername());
} }
List<Tag> tags = tagsService.findByDId(id); List<Tag> tags = tagsService.findByDId(id);
List postsObj = postsService.findPostCustomById(id); List postsObj = postsService.findPostCustomById(id);
map.put("tags", tags); map.put("tags", tags);
@@ -114,14 +122,12 @@ public class UserPostController extends BaseController {
discussion.setCreateId(user.getId()); discussion.setCreateId(user.getId());
} }
discussion.setCreateTime(new Date()); discussion.setCreateTime(new Date());
discussion.setStartTime(new Date()); discussion.setStartTime(new Date());
discussion.setLastTime(new Date()); discussion.setLastTime(new Date());
Discussion discussionOne = new Discussion(); Discussion discussionOne = new Discussion();
BeanUtils.copyProperties(discussion, discussionOne); BeanUtils.copyProperties(discussion, discussionOne);
Discussion saveDiscussion = discussionsService.insert(discussionOne); Discussion saveDiscussion = discussionsService.insert(discussionOne);
if (null != discussion.getTag()) { if (null != discussion.getTag()) {
@@ -138,7 +144,7 @@ public class UserPostController extends BaseController {
JSONObject resultobj = new JSONObject(); JSONObject resultobj = new JSONObject();
logger.info(">>>{}", saveDiscussion); logger.info(">>>{}", saveDiscussion);
resultobj.put("msg", "添加成功"); resultobj.put("msg", "添加主题成功");
resultobj.put("flag", true); resultobj.put("flag", true);
return resultobj.toString(); // return resultobj.toString(); //
@@ -178,14 +184,13 @@ public class UserPostController extends BaseController {
if (null != post.getParentId()) { if (null != post.getParentId()) {
Post temp = postsService.findOneByid(post.getParentId()); Post temp = postsService.findOneByid(post.getParentId());
post.setUserId(temp.getCreateId()); post.setUserId(temp.getCreateId());
} }
Post savePost = postsService.insert(post); Post savePost = postsService.insert(post);
JSONObject resultobj = new JSONObject(); JSONObject resultobj = new JSONObject();
logger.info(">>>{}", savePost); logger.info(">>>{}", savePost);
resultobj.put("msg", "添加成功"); resultobj.put("msg", "添加评论成功");
resultobj.put("flag", true); resultobj.put("flag", true);
return resultobj.toString(); // return resultobj.toString(); //
} }
@@ -205,7 +210,6 @@ public class UserPostController extends BaseController {
@ResponseBody @ResponseBody
public String newTags(@RequestBody Tag tag) { public String newTags(@RequestBody Tag tag) {
logger.info(">>> newTags" + tag); logger.info(">>> newTags" + tag);
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = servletRequestAttributes.getRequest(); HttpServletRequest request = servletRequestAttributes.getRequest();
@@ -219,13 +223,14 @@ public class UserPostController extends BaseController {
JSONObject resultobj = new JSONObject(); JSONObject resultobj = new JSONObject();
logger.info(">>>{}", saveTag); logger.info(">>>{}", saveTag);
resultobj.put("msg", "添加成功"); resultobj.put("msg", "添加标签成功");
resultobj.put("flag", true); resultobj.put("flag", true);
return resultobj.toString(); // return resultobj.toString();
} }
//排行榜等 /**
* 排行榜等
*/
/** /**
* 新建主题页 * 新建主题页
@@ -236,7 +241,6 @@ public class UserPostController extends BaseController {
*/ */
@RequestMapping({"/newDiscussionsPage"}) @RequestMapping({"/newDiscussionsPage"})
public String newdiccuss(HttpServletRequest request, ModelMap map) { public String newdiccuss(HttpServletRequest request, ModelMap map) {
//获取所有标签(以后尝试去缓存中取) //获取所有标签(以后尝试去缓存中取)
List<Tag> allTags = tagsService.getAllListDiscussions(); List<Tag> allTags = tagsService.getAllListDiscussions();
map.put("allTags", allTags); map.put("allTags", allTags);
@@ -30,11 +30,11 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* @author yaoyuan2.chu
* 首页页面系统控制器 * 首页页面系统控制器
*/ */
@Controller @Controller
public class UserSystemController extends BaseController { public class UserSystemController extends BaseController {
private static Logger logger = LoggerFactory.getLogger(UserSystemController.class); private static Logger logger = LoggerFactory.getLogger(UserSystemController.class);
@Autowired @Autowired
@@ -48,7 +48,6 @@ public class UserSystemController extends BaseController {
/** /**
* 首页index * 首页index
*
* @param tag * @param tag
* @param type * @param type
* @param pageNum * @param pageNum
@@ -62,7 +61,6 @@ public class UserSystemController extends BaseController {
logger.info(">>> index"); logger.info(">>> index");
logger.info(">>> tag:" + tag); logger.info(">>> tag:" + tag);
logger.info(">>> pageNum:" + pageNum); logger.info(">>> pageNum:" + pageNum);
int pageSiz = 10; int pageSiz = 10;
int pageNumNew = pageNum - 1; int pageNumNew = pageNum - 1;
Discussion discussion = new Discussion(); Discussion discussion = new Discussion();
@@ -71,14 +69,12 @@ public class UserSystemController extends BaseController {
List<Discussion> allDiscussions = allDiscussionsPage.getContent(); List<Discussion> allDiscussions = allDiscussionsPage.getContent();
List<DiscussionCustom> newAllD = new ArrayList<>(); List<DiscussionCustom> newAllD = new ArrayList<>();
setTagAndUserList(newAllD, allDiscussions); setTagAndUserList(newAllD, allDiscussions);
logger.info("全部主题==>{}", allDiscussions); logger.info("全部主题==>{}", allDiscussions);
Long total = allDiscussionsPage.getTotalElements(); Long total = allDiscussionsPage.getTotalElements();
//获取主题帖子的分页数据 //获取主题帖子的分页数据(以后尝试去缓存中取)
List<String> pageNumList = getPageNumList(allDiscussionsPage.getTotalPages()); List<String> pageNumList = getPageNumList(allDiscussionsPage.getTotalPages());
//获取所有标签(以后尝试去缓存中取) //获取所有标签(以后尝试去缓存中取)
@@ -216,7 +212,6 @@ public class UserSystemController extends BaseController {
/** /**
* 注册提交 * 注册提交
*
* @param username * @param username
* @param email * @param email
* @param password * @param password
@@ -232,7 +227,6 @@ public class UserSystemController extends BaseController {
return "register"; return "register";
} else { } else {
User user = new User(); User user = new User();
user.setEmail(email); user.setEmail(email);
user.setPassword(password); user.setPassword(password);
user.setUsername(username); user.setUsername(username);
@@ -254,7 +248,6 @@ public class UserSystemController extends BaseController {
return "register"; return "register";
} }
//获取设置信息 //获取设置信息
//获取首页统计 //获取首页统计
@@ -36,7 +36,6 @@ public class RestPostController {
} else { } else {
throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST); throw new BaseException(ResponseCode.RESOURCES_NOT_EXIST);
} }
} }
@GetMapping("/discussion/{id}") @GetMapping("/discussion/{id}")
@@ -6,6 +6,7 @@ import com.yaoyuan.jiscuss.response.ResponseCode;
import com.yaoyuan.jiscuss.service.IUsersService; import com.yaoyuan.jiscuss.service.IUsersService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -16,13 +16,21 @@ public class BaseException extends RuntimeException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private ResponseCode code; private ResponseCode code;
/**
* BaseException
* ResponseCode code
**/
public BaseException(ResponseCode code) { public BaseException(ResponseCode code) {
this.code = code; this.code = code;
} }
/**
* BaseException
* ResponseCode code
* Throwable cause
**/
public BaseException(Throwable cause, ResponseCode code) { public BaseException(Throwable cause, ResponseCode code) {
super(cause); super(cause);
this.code = code; this.code = code;
@@ -15,7 +15,6 @@ public interface TagsRepository extends JpaRepository<Tag, Integer> {
@Query(value = "FROM Tag a, DiscussionTag b WHERE a.id = b.tagId and b.discussionId = :dId") @Query(value = "FROM Tag a, DiscussionTag b WHERE a.id = b.tagId and b.discussionId = :dId")
List<Tag> findByDId(@Param("dId") Integer dId); List<Tag> findByDId(@Param("dId") Integer dId);
@Query("select new com.yaoyuan.jiscuss.entity.custom.TagCustom(" + @Query("select new com.yaoyuan.jiscuss.entity.custom.TagCustom(" +
"u.name,u.color,u.icon,u.description, d.discussionId" + "u.name,u.color,u.icon,u.description, d.discussionId" +
") " + ") " +
@@ -8,7 +8,6 @@ import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@Repository @Repository
public interface UsersRepository extends JpaRepository<User, Integer> { public interface UsersRepository extends JpaRepository<User, Integer> {
/** /**
@@ -38,5 +37,4 @@ public interface UsersRepository extends JpaRepository<User, Integer> {
*/ */
@Query("from User where username = :username and password = :password") @Query("from User where username = :username and password = :password")
User checkByUsernameAndPassword(String username, String password); User checkByUsernameAndPassword(String username, String password);
} }
@@ -15,9 +15,8 @@ import java.io.Serializable;
@AllArgsConstructor @AllArgsConstructor
public class ResponseResult implements Serializable { public class ResponseResult implements Serializable {
/** /**
* * serialVersionUID
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -2,7 +2,6 @@ package com.yaoyuan.jiscuss.service;
import com.yaoyuan.jiscuss.entity.User; import com.yaoyuan.jiscuss.entity.User;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import java.util.List; import java.util.List;
public interface IUsersService { public interface IUsersService {
@@ -11,6 +10,7 @@ public interface IUsersService {
Page<User> queryAllUsersList(int pageNum, int pageSize); Page<User> queryAllUsersList(int pageNum, int pageSize);
//Cacheable
List<User> getByUsernameIsLike(String name); List<User> getByUsernameIsLike(String name);
//@Cacheable("myCache") //@Cacheable("myCache")
@@ -27,5 +27,4 @@ public interface IUsersService {
User checkByUsernameAndPassword(String username, String password); User checkByUsernameAndPassword(String username, String password);
User update(User user, Integer id); User update(User user, Integer id);
} }
@@ -12,6 +12,7 @@ import java.util.List;
@Service @Service
@Transactional @Transactional
public class DiscussionsTagsServiceImpl implements IDiscussionsTagsService { public class DiscussionsTagsServiceImpl implements IDiscussionsTagsService {
@Autowired @Autowired
private DiscussionsTagsRepository discussionsTagsRepository; private DiscussionsTagsRepository discussionsTagsRepository;
@@ -24,6 +25,4 @@ public class DiscussionsTagsServiceImpl implements IDiscussionsTagsService {
public DiscussionTag insert(DiscussionTag discussionTag) { public DiscussionTag insert(DiscussionTag discussionTag) {
return discussionsTagsRepository.save(discussionTag); return discussionsTagsRepository.save(discussionTag);
} }
} }
@@ -17,10 +17,10 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
@Service @Service
@Transactional @Transactional
public class PostsServiceImpl implements IPostsService { public class PostsServiceImpl implements IPostsService {
@Autowired @Autowired
private PostsRepository postsRepository; private PostsRepository postsRepository;
@@ -31,7 +31,6 @@ public class PostsServiceImpl implements IPostsService {
@Override @Override
public List<Post> findOneBy(Integer id) { public List<Post> findOneBy(Integer id) {
List<Post> posts = postsRepository.findOneBy(id); List<Post> posts = postsRepository.findOneBy(id);
return posts; return posts;
} }
@@ -49,19 +48,14 @@ public class PostsServiceImpl implements IPostsService {
public List findPostCustomById(Integer id) { public List findPostCustomById(Integer id) {
//查询id为1且parentId为null的评论 //查询id为1且parentId为null的评论
List<Map<String, Object>> firstposts = postsRepository.findAllByDIdAndparentIdNull(id); List<Map<String, Object>> firstposts = postsRepository.findAllByDIdAndparentIdNull(id);
List<PostCustom> firstpostCustomList = PostCommonUtil.getNewPostsObjMap(firstposts); List<PostCustom> firstpostCustomList = PostCommonUtil.getNewPostsObjMap(firstposts);
// List<PostCustom> firstpostCustomListNew = PostCommonUtil.getNewPostsObjCustom(firstpostCustomList); // List<PostCustom> firstpostCustomListNew = PostCommonUtil.getNewPostsObjCustom(firstpostCustomList);
//查询id为1且parentId不为null的评论 //查询id为1且parentId不为null的评论
List<Map<String, Object>> thenposts = postsRepository.findAllByDIdAndparentIdNotNull(id); List<Map<String, Object>> thenposts = postsRepository.findAllByDIdAndparentIdNotNull(id);
List<PostCustom> thenpostCustomList = PostCommonUtil.getNewPostsObjMap(thenposts); List<PostCustom> thenpostCustomList = PostCommonUtil.getNewPostsObjMap(thenposts);
// List<PostCustom> thenpostCustomListNew = PostCommonUtil.getNewPostsObjCustom(thenpostCustomList); // List<PostCustom> thenpostCustomListNew = PostCommonUtil.getNewPostsObjCustom(thenpostCustomList);
//新建一个Node集合。 //新建一个Node集合。
ArrayList<Node> nodes = new ArrayList<>(); ArrayList<Node> nodes = new ArrayList<>();
//将第一层评论都添加都Node集合中 //将第一层评论都添加都Node集合中
@@ -76,17 +70,12 @@ public class PostsServiceImpl implements IPostsService {
//打印回复链表 //打印回复链表
Node.show(list); Node.show(list);
// List<Map<String, Object>> posts = postsRepository.findPostCustomById(id); // List<Map<String, Object>> posts = postsRepository.findPostCustomById(id);
//
// List<PostCustom> postCustomList = PostCommonUtil.getNewPostsObjMap(posts); // List<PostCustom> postCustomList = PostCommonUtil.getNewPostsObjMap(posts);
//
// List<PostCustom> postCustomListNew = PostCommonUtil.getNewPostsObjCustom(postCustomList); // List<PostCustom> postCustomListNew = PostCommonUtil.getNewPostsObjCustom(postCustomList);
return list; return list;
} }
@Override @Override
public Post insert(Post post) { public Post insert(Post post) {
return postsRepository.save(post); return postsRepository.save(post);
@@ -1,6 +1,5 @@
package com.yaoyuan.jiscuss.service.impl; package com.yaoyuan.jiscuss.service.impl;
import com.yaoyuan.jiscuss.entity.User; import com.yaoyuan.jiscuss.entity.User;
import com.yaoyuan.jiscuss.repository.UsersRepository; import com.yaoyuan.jiscuss.repository.UsersRepository;
import com.yaoyuan.jiscuss.service.IUsersService; import com.yaoyuan.jiscuss.service.IUsersService;
@@ -20,6 +19,7 @@ import java.util.List;
@Service @Service
@Transactional @Transactional
public class UsersServiceImpl implements IUsersService { public class UsersServiceImpl implements IUsersService {
@Autowired @Autowired
private UsersRepository usersRepository; private UsersRepository usersRepository;
@@ -110,6 +110,7 @@ public class UsersServiceImpl implements IUsersService {
/** /**
* 删除所有 * 删除所有
*
*/ */
@Override @Override
public void deleteAll() { public void deleteAll() {
@@ -2,15 +2,11 @@ package com.yaoyuan.jiscuss.util;
/** /**
* @author yaoyuan2.chu * @author yaoyuan2.chu
* @Title: * @Title: 去除内容页代码里的HTML标签
* @Package com.yaoyuan.jiscuss.util * @Package com.yaoyuan.jiscuss.util
* @Description: * @Description:
* @date 2020/8/31 20:52 * @date 2020/8/31 20:52
*/ */
/**
* 去除内容页代码里的HTML标签
*/
public class DelTagsUtil { public class DelTagsUtil {
/** /**
* 去除html代码中含有的标签 * 去除html代码中含有的标签
@@ -54,8 +50,7 @@ public class DelTagsUtil {
} }
public static void main(String[] args) { public static void main(String[] args) {
String htmlStr = "<script type>var i=1; alert(i)</script><style> .font1{font-size:12px}</style><span>少年中国说。</span>红日初升,其道大光。<h3>河出伏流,一泻汪洋。</h3>潜龙腾渊, 鳞爪飞扬。乳 虎啸 谷,百兽震惶。鹰隼试翼,风尘吸张。奇花初胎,矞矞皇皇。干将发硎,有作其芒。天戴其苍,地履其黄。纵有千古,横有" + String htmlStr = "test";
"八荒。<a href=\"www.baidu.com\">前途似海,来日方长</a>。<h1>美哉我少年中国,与天不老!</h1><p>壮哉我中国少年,与国无疆!</p>";
System.out.println(getTextFromHtml(htmlStr)); System.out.println(getTextFromHtml(htmlStr));
} }
+2 -5
View File
@@ -5,7 +5,6 @@
<!-- <link rel="stylesheet" type="text/css" href="static/semanticui/semantic.css"> --> <!-- <link rel="stylesheet" type="text/css" href="static/semanticui/semantic.css"> -->
<!-- <script src="static/jquery/jquery-3.4.1.min.js"></script> --> <!-- <script src="static/jquery/jquery-3.4.1.min.js"></script> -->
<!-- <script src="static/semanticui/semantic.min.js"></script> --> <!-- <script src="static/semanticui/semantic.min.js"></script> -->
<!-- default header name is X-CSRF-TOKEN --> <!-- default header name is X-CSRF-TOKEN -->
<meta name="_csrf" content="${_csrf.token}"/> <meta name="_csrf" content="${_csrf.token}"/>
<meta name="_csrf_header" content="${_csrf.headerName}"/> <meta name="_csrf_header" content="${_csrf.headerName}"/>
@@ -30,7 +29,6 @@
<div class="ui four column grid"> <div class="ui four column grid">
<div class="ui widescreen large screen computer tablet only twelve wide column"> <div class="ui widescreen large screen computer tablet only twelve wide column">
<div id="context2" style="padding-left: 14px; padding-right: 14px;background: #FFFFFF; padding: 1em 1em; border-radius: 0.28571429rem; border: 1px solid rgba(34, 36, 38, 0.15);"> <div id="context2" style="padding-left: 14px; padding-right: 14px;background: #FFFFFF; padding: 1em 1em; border-radius: 0.28571429rem; border: 1px solid rgba(34, 36, 38, 0.15);">
<h2 class="ui header"> <h2 class="ui header">
<i class="edit outline icon"></i> <i class="edit outline icon"></i>
<div class="content"> <div class="content">
@@ -198,14 +196,14 @@
<div class="ui card"> <div class="ui card">
<div class="content"> <div class="content">
<div class="header">作者热门主题</div> <div class="header">作者热门主题</div>
</div> </div>
<div class="content"> <div class="content">
<div class="ui middle aligned divided list"> <div class="ui middle aligned divided list">
<div class="item"> <div class="item">
<img class="ui avatar image" src="/static/assets/images/logo.png"> <img class="ui avatar image" src="/static/assets/images/logo.png">
<div class="content"> <div class="content">
<a class="header">他的测试主题1</a> <a class="header">its here</a>
</div> </div>
</div> </div>
<div class="item"> <div class="item">
@@ -301,7 +299,6 @@
console.log('已经登陆:' + username); console.log('已经登陆:' + username);
</#if> </#if>
setDiscussionsId('${discussions.id}'); setDiscussionsId('${discussions.id}');
}); });
</script> </script>
+1 -1
View File
@@ -3,7 +3,6 @@
<title>Jiscuss Demo</title> <title>Jiscuss Demo</title>
<head> <head>
<#include "comm/commjs.ftl"/> <#include "comm/commjs.ftl"/>
<style type="text/css"> <style type="text/css">
body { body {
background-color: #f7f8fa; background-color: #f7f8fa;
@@ -52,6 +51,7 @@
${msg} ${msg}
</div> </div>
</div> </div>
<button class="ui fluid large blue button" type="submit">登 录</button> <button class="ui fluid large blue button" type="submit">登 录</button>
</div> </div>
+1 -6
View File
@@ -5,13 +5,10 @@
<!-- <link rel="stylesheet" type="text/css" href="static/semanticui/semantic.css"> --> <!-- <link rel="stylesheet" type="text/css" href="static/semanticui/semantic.css"> -->
<!-- <script src="static/jquery/jquery-3.4.1.min.js"></script> --> <!-- <script src="static/jquery/jquery-3.4.1.min.js"></script> -->
<!-- <script src="static/semanticui/semantic.min.js"></script> --> <!-- <script src="static/semanticui/semantic.min.js"></script> -->
<!-- default header name is X-CSRF-TOKEN --> <!-- default header name is X-CSRF-TOKEN -->
<meta name="_csrf" content="${_csrf.token}"/> <meta name="_csrf" content="${_csrf.token}"/>
<meta name="_csrf_header" content="${_csrf.headerName}"/> <meta name="_csrf_header" content="${_csrf.headerName}"/>
<#include "comm/commjs.ftl"/> <#include "comm/commjs.ftl"/>
</head> </head>
<body> <body>
<div class="ui container" id="container"> <div class="ui container" id="container">
@@ -35,7 +32,6 @@
&nbsp;<button class="ui teal button" onclick="onNewtags()">新增标签</button> &nbsp;<button class="ui teal button" onclick="onNewtags()">新增标签</button>
</div> </div>
<div class="field"> <div class="field">
<label>内容</label> <label>内容</label>
<textarea id="discussionsContent"></textarea> <textarea id="discussionsContent"></textarea>
@@ -70,6 +66,7 @@
}); });
} }
//点击事件
$("#newDiscussions").click(function () { $("#newDiscussions").click(function () {
var token = $("meta[name='_csrf']").attr("content"); var token = $("meta[name='_csrf']").attr("content");
@@ -114,8 +111,6 @@
}); });
}); });
</script> </script>
</body> </body>