代码提交
This commit is contained in:
@@ -42,7 +42,8 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
|
|||||||
"/css/**",
|
"/css/**",
|
||||||
"/js/**",
|
"/js/**",
|
||||||
"/images/**",
|
"/images/**",
|
||||||
"/static/**"
|
"/static/**",
|
||||||
|
"/h2-console/**"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ public class UserPostController extends BaseController {
|
|||||||
|
|
||||||
List<Posts> posts = postsService.findOneBy(id);
|
List<Posts> posts = postsService.findOneBy(id);
|
||||||
|
|
||||||
|
List<Tags> tags = tagsService.findByDId(id);
|
||||||
|
|
||||||
//查询id为1且parentId为null的评论
|
//查询id为1且parentId为null的评论
|
||||||
List<Posts> firstList = postsService.findAllByDIdAndparentIdNull(1);
|
List<Posts> firstList = postsService.findAllByDIdAndparentIdNull(1);
|
||||||
//查询id为1且parentId不为null的评论
|
//查询id为1且parentId不为null的评论
|
||||||
|
|||||||
@@ -7,8 +7,11 @@ import com.yaoyuan.jiscuss.entity.Users;
|
|||||||
import com.yaoyuan.jiscuss.service.IDiscussionsService;
|
import com.yaoyuan.jiscuss.service.IDiscussionsService;
|
||||||
import com.yaoyuan.jiscuss.service.ITagsService;
|
import com.yaoyuan.jiscuss.service.ITagsService;
|
||||||
import com.yaoyuan.jiscuss.service.IUsersService;
|
import com.yaoyuan.jiscuss.service.IUsersService;
|
||||||
|
import com.yaoyuan.jiscuss.util.DelTagsUtil;
|
||||||
|
import org.apache.catalina.mbeans.MBeanUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
@@ -51,13 +54,28 @@ public class UserSystemController extends BaseController {
|
|||||||
List<Users> useral2 = usersService.getAllList();
|
List<Users> useral2 = usersService.getAllList();
|
||||||
logger.info(">>> 第二遍的全部用户:"+useral2);
|
logger.info(">>> 第二遍的全部用户:"+useral2);
|
||||||
|
|
||||||
int pageSiz = 5;
|
int pageSiz = 10;
|
||||||
int pageNumNew = pageNum - 1;
|
int pageNumNew = pageNum - 1;
|
||||||
Discussions discussions = new Discussions();
|
Discussions discussions = new Discussions();
|
||||||
//分页获取主题帖子
|
//分页获取主题帖子
|
||||||
Page<Discussions> allDiscussionsPage = discussionsService.queryAllDiscussionsList(discussions,pageNumNew,pageSiz);
|
Page<Discussions> allDiscussionsPage = discussionsService.queryAllDiscussionsList(discussions,pageNumNew,pageSiz);
|
||||||
|
|
||||||
List<Discussions> allDiscussions =allDiscussionsPage.getContent();
|
List<Discussions> allDiscussions = allDiscussionsPage.getContent();
|
||||||
|
List<Discussions> newAllD = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Discussions dd : allDiscussions){
|
||||||
|
Discussions newdd = new Discussions();
|
||||||
|
BeanUtils.copyProperties(dd , newdd);
|
||||||
|
String newCon = "";
|
||||||
|
String content = DelTagsUtil.getTextFromHtml(newdd.getContent());
|
||||||
|
if(null != content && content.length()>30){
|
||||||
|
newCon = content.substring(0,29);
|
||||||
|
}else{
|
||||||
|
newCon = content;
|
||||||
|
}
|
||||||
|
newdd.setContent(newCon);
|
||||||
|
newAllD.add(newdd);
|
||||||
|
}
|
||||||
|
|
||||||
logger.info("全部主题==>:{}",allDiscussions);
|
logger.info("全部主题==>:{}",allDiscussions);
|
||||||
|
|
||||||
@@ -72,7 +90,7 @@ public class UserSystemController extends BaseController {
|
|||||||
|
|
||||||
System.out.println(userall.toString());
|
System.out.println(userall.toString());
|
||||||
map.put("data", "Jiscuss 用户");
|
map.put("data", "Jiscuss 用户");
|
||||||
map.put("allDiscussions", allDiscussions);
|
map.put("allDiscussions", newAllD);
|
||||||
map.put("pageDiscussions", pageNumList);
|
map.put("pageDiscussions", pageNumList);
|
||||||
map.put("allTags", allTags);
|
map.put("allTags", allTags);
|
||||||
map.put("tag", tag);
|
map.put("tag", tag);
|
||||||
|
|||||||
@@ -1,10 +1,17 @@
|
|||||||
package com.yaoyuan.jiscuss.repository;
|
package com.yaoyuan.jiscuss.repository;
|
||||||
|
|
||||||
|
import com.yaoyuan.jiscuss.entity.Posts;
|
||||||
import com.yaoyuan.jiscuss.entity.Tags;
|
import com.yaoyuan.jiscuss.entity.Tags;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface TagsRepository extends JpaRepository<Tags,Integer> {
|
public interface TagsRepository extends JpaRepository<Tags,Integer> {
|
||||||
|
|
||||||
|
@Query(value = "FROM Tags a, DiscussionsTags b WHERE a.id = b.tagId and b.discussionId = :dId")
|
||||||
|
List<Tags> findByDId(@Param("dId")Integer dId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,4 +9,6 @@ public interface ITagsService {
|
|||||||
List<Tags> getAllList();
|
List<Tags> getAllList();
|
||||||
|
|
||||||
Tags insert(Tags tags);
|
Tags insert(Tags tags);
|
||||||
|
|
||||||
|
List<Tags> findByDId(Integer id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Example;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.yaoyuan.jiscuss.entity.Tags;
|
import com.yaoyuan.jiscuss.entity.Tags;
|
||||||
@@ -26,6 +27,11 @@ public class TagsServiceImpl implements ITagsService {
|
|||||||
public Tags insert(Tags tags) {
|
public Tags insert(Tags tags) {
|
||||||
return tagsRepository.save(tags);
|
return tagsRepository.save(tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Tags> findByDId(Integer id) {
|
||||||
|
return tagsRepository.findByDId(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package com.yaoyuan.jiscuss.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yaoyuan2.chu
|
||||||
|
* @Title:
|
||||||
|
* @Package com.yaoyuan.jiscuss.util
|
||||||
|
* @Description:
|
||||||
|
* @date 2020/8/31 20:52
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* 去除内容页代码里的HTML标签
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class DelTagsUtil {
|
||||||
|
/**
|
||||||
|
* 去除html代码中含有的标签
|
||||||
|
* @param htmlStr
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String delHtmlTags(String htmlStr) {
|
||||||
|
//定义script的正则表达式,去除js可以防止注入
|
||||||
|
String scriptRegex="<script[^>]*?>[\\s\\S]*?<\\/script>";
|
||||||
|
//定义style的正则表达式,去除style样式,防止css代码过多时只截取到css样式代码
|
||||||
|
String styleRegex="<style[^>]*?>[\\s\\S]*?<\\/style>";
|
||||||
|
//定义HTML标签的正则表达式,去除标签,只提取文字内容
|
||||||
|
String htmlRegex="<[^>]+>";
|
||||||
|
//定义空格,回车,换行符,制表符
|
||||||
|
String spaceRegex = "\\s*|\t|\r|\n";
|
||||||
|
|
||||||
|
// 过滤script标签
|
||||||
|
htmlStr = htmlStr.replaceAll(scriptRegex, "");
|
||||||
|
// 过滤style标签
|
||||||
|
htmlStr = htmlStr.replaceAll(styleRegex, "");
|
||||||
|
// 过滤html标签
|
||||||
|
htmlStr = htmlStr.replaceAll(htmlRegex, "");
|
||||||
|
// 过滤空格等
|
||||||
|
htmlStr = htmlStr.replaceAll(spaceRegex, "");
|
||||||
|
return htmlStr.trim(); // 返回文本字符串
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取HTML代码里的内容
|
||||||
|
* @param htmlStr
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getTextFromHtml(String htmlStr){
|
||||||
|
//去除html标签
|
||||||
|
htmlStr = delHtmlTags(htmlStr);
|
||||||
|
//去除空格" "
|
||||||
|
htmlStr = htmlStr.replaceAll(" ","");
|
||||||
|
return htmlStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
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>潜龙腾渊, 鳞爪飞扬。乳 虎啸 谷,百兽震惶。鹰隼试翼,风尘吸张。奇花初胎,矞矞皇皇。干将发硎,有作其芒。天戴其苍,地履其黄。纵有千古,横有" +
|
||||||
|
"八荒。<a href=\"www.baidu.com\">前途似海,来日方长</a>。<h1>美哉我少年中国,与天不老!</h1><p>壮哉我中国少年,与国无疆!</p>";
|
||||||
|
System.out.println(getTextFromHtml(htmlStr));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -47,4 +47,4 @@ spring:
|
|||||||
mvc:
|
mvc:
|
||||||
static-path-pattern: /static/**
|
static-path-pattern: /static/**
|
||||||
server:
|
server:
|
||||||
port: 8081
|
port: 80
|
||||||
@@ -49,19 +49,19 @@ values (1, '测试标签1',null,null,null,null,null,null,null,null,null);
|
|||||||
|
|
||||||
|
|
||||||
insert into posts
|
insert into posts
|
||||||
values (1, 1, 1,null,1,null,'评论内容222',null,null,1,null,null,null,null);
|
values (1, 1, 1,null,1,null,'评论内容222',null,null,null,null,null,null,null,null);
|
||||||
|
|
||||||
insert into posts
|
insert into posts
|
||||||
values (2, 1, 2,null,1,null,'评论内容333',null,null,1,null,null,null,null);
|
values (2, 1, 2,null,1,null,'评论内容333',null,null,1,null,null,null,null,null);
|
||||||
|
|
||||||
insert into posts
|
insert into posts
|
||||||
values (3, 1, 3,null,1,1,'评论内容444',null,null,1,null,null,null,null);
|
values (3, 1, 3,null,1,1,'评论内容444',null,null,1,null,null,null,null,null);
|
||||||
|
|
||||||
insert into posts
|
insert into posts
|
||||||
values (4, 1, 4,null,1,1,'评论内容555',null,null,1,null,null,null,null);
|
values (4, 1, 4,null,1,1,'评论内容555',null,null,null,null,null,null,null,null);
|
||||||
|
|
||||||
insert into posts
|
insert into posts
|
||||||
values (5, 1, 5,null,1,2,'评论内容666',null,null,1,null,null,null,null);
|
values (5, 1, 5,null,1,null,'评论内容666',null,null,4,null,null,null,null,null);
|
||||||
|
|
||||||
insert into posts
|
insert into posts
|
||||||
values (6, 1, 6,null,1,5,'评论内容777',null,null,1,null,null,null,null);
|
values (6, 1, 6,null,1,null,'评论内容777',null,null,5,null,null,null,null,null);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
<div id="context2">
|
<div id="context2">
|
||||||
|
|
||||||
<h2 class="ui header">
|
<h2 class="ui header">
|
||||||
<i class="settings icon"></i>
|
<i class="save outline"></i>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
${discussions.title}
|
${discussions.title}
|
||||||
<div class="sub header">某某标签分类</div>
|
<div class="sub header">某某标签分类</div>
|
||||||
@@ -57,12 +57,12 @@
|
|||||||
<div class="summary">
|
<div class="summary">
|
||||||
用户 <a>测试人员1</a> 发布于
|
用户 <a>测试人员1</a> 发布于
|
||||||
<div class="date">
|
<div class="date">
|
||||||
3 days ago
|
${discussions.createTime}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="meta">
|
<div class="meta">
|
||||||
<a class="like">
|
<a class="like">
|
||||||
<i class="like icon"></i> 4 喜欢
|
<i class="like icon"></i> 0 喜欢
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -368,26 +368,37 @@
|
|||||||
<i class="left chevron icon"></i>
|
<i class="left chevron icon"></i>
|
||||||
</a>
|
</a>
|
||||||
<#list pageDiscussions as page>
|
<#list pageDiscussions as page>
|
||||||
<#if page == pageNum >
|
<#if page == pageNum && !(username)??>
|
||||||
<a class="item" style=" background-color: #7d827d;" href="/?pageNum=${page}">
|
<a class="item" style=" background-color: #7d827d;" href="/?pageNum=${page}">
|
||||||
${page}
|
${page}
|
||||||
</a>
|
</a>
|
||||||
<#else>
|
</#if>
|
||||||
|
<#if page != pageNum && !(username)??>
|
||||||
<a class="item" href="/?pageNum=${page}">
|
<a class="item" href="/?pageNum=${page}">
|
||||||
${page}
|
${page}
|
||||||
</a>
|
</a>
|
||||||
</#if>
|
</#if>
|
||||||
|
<#if page == pageNum && username??>
|
||||||
|
<a class="item" style=" background-color: #7d827d;" href="/main?pageNum=${page}">
|
||||||
|
${page}
|
||||||
|
</a>
|
||||||
|
</#if>
|
||||||
|
<#if page != pageNum && username??>
|
||||||
|
<a class="item" href="/main?pageNum=${page}">
|
||||||
|
${page}
|
||||||
|
</a>
|
||||||
|
</#if>
|
||||||
</#list>
|
</#list>
|
||||||
<a class="icon item" id="nextPage"> <i class="right chevron icon"></i>
|
<a class="icon item" id="nextPage"> <i class="right chevron icon"></i>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<!--pager-->
|
<!--pager-->
|
||||||
<div class="ui borderless menu">
|
<#--<div class="ui borderless menu">
|
||||||
<ul class="pagination">
|
<ul class="pagination">
|
||||||
<#import "./comm/page.ftl" as page />
|
<#import "./comm/page.ftl" as page />
|
||||||
<@page.fpage page=pageNum pagesize=pageSize totalpages=pageTotalPages totalrecords=pageTotal url="/?type="+${type}+"&tag="+${tag}+"" />
|
<@page.fpage page=pageNum pagesize=pageSize totalpages=pageTotalPages totalrecords=pageTotal url="/" />
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>-->
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user