提交 2645780b 编写于 作者: U u014427391

fixed #修复fastjson解析数据出现$ref问题

上级 361f9c31
package net.myblog.entity.dto;
import net.myblog.entity.Article;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Set;
/**
* @author nicky
* @date 2019-01-07
*/
@Table(name="article_sort")
@Entity
public class ArticleSortDto implements Serializable{
/** 文章栏目Id**/
private int typeId;
/** 栏目名称**/
private String name;
private Set<Article> articles;
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Id
public int getTypeId() {
return typeId;
}
public void setTypeId(int typeId) {
this.typeId = typeId;
}
@Column(length=100, nullable=false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package net.myblog.entity.vo;
import net.myblog.entity.Article;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Set;
/**
* @author nicky
* @date 2019-01-07
*/
@Table(name="article_sort")
@Entity
public class ArticleSortVo implements Serializable{
/** 文章栏目Id**/
private int typeId;
/** 栏目名称**/
private String name;
private Set<Article> articles;
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Id
public int getTypeId() {
return typeId;
}
public void setTypeId(int typeId) {
this.typeId = typeId;
}
@Column(length=100, nullable=false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
......@@ -6,14 +6,15 @@ import javax.persistence.QueryHint;
import net.myblog.entity.ArticleSort;
import net.myblog.entity.dto.ArticleSortDto;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.QueryHints;
public interface ArticleSortRepository extends JpaRepository<ArticleSort,Integer>{
public interface ArticleSortRepository extends JpaRepository<ArticleSortDto,Integer>{
/**启用setHint缓存,查询一次,之后缓存处理**/
@Query("FROM ArticleSort")
@Query("FROM ArticleSortDto")
@QueryHints({@QueryHint(name=org.hibernate.ejb.QueryHints.HINT_CACHEABLE,value="true")})
List<ArticleSort> getAll();
List<ArticleSortDto> getAll();
}
package net.myblog.service;
import java.util.List;
import net.myblog.entity.ArticleSort;
import net.myblog.entity.dto.ArticleSortDto;
import net.myblog.repository.ArticleSortRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
public class ArticleSortService {
......@@ -19,7 +18,7 @@ public class ArticleSortService {
* @return
*/
@Transactional(readOnly=true)
public List<ArticleSort> findAll(){
public List<ArticleSortDto> findAll(){
return articleSortRepository.findAll();
}
......
package net.myblog.web.controller;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSONArray;
import net.myblog.core.Constants;
import net.myblog.core.lucene.HighlighterBuilder;
import net.myblog.core.lucene.LuceneSearchEnginer;
import net.myblog.entity.Advertisement;
import net.myblog.entity.Article;
import net.myblog.entity.ArticleSort;
import net.myblog.entity.FriendlyLink;
import net.myblog.entity.dto.ArticleSortDto;
import net.myblog.service.AdvertisementService;
import net.myblog.service.ArticleService;
import net.myblog.service.ArticleSortService;
import net.myblog.service.FriendlyLinkService;
import net.myblog.utils.DateUtils;
import net.myblog.utils.Tools;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.document.Document;
......@@ -33,12 +22,7 @@ import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.*;
import org.apache.lucene.search.highlight.Highlighter;
import org.apache.lucene.search.highlight.InvalidTokenOffsetsException;
import org.apache.lucene.search.highlight.QueryScorer;
......@@ -46,19 +30,24 @@ import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.wltea.analyzer.lucene.IKAnalyzer;
import com.alibaba.fastjson.JSONArray;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@Controller
public class BlogIndexController extends BaseController{
......@@ -105,7 +94,7 @@ public class BlogIndexController extends BaseController{
supportArticles = articlesTemp;
}
//获取文章类别标签
List<ArticleSort> articleSorts = articleSortService.findAll();
List<ArticleSortDto> articleSorts = articleSortService.findAll();
//获取友情链接信息
List<FriendlyLink> links = friendlyLinkService.findAll();
//获取广告信息
......
package net.myblog.web.controller.admin;
import java.util.List;
import com.alibaba.fastjson.JSONArray;
import net.myblog.entity.ArticleSort;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import net.myblog.entity.dto.ArticleSortDto;
import net.myblog.service.ArticleSortService;
import net.myblog.web.controller.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
/**
* @description 博客标签(类别)信息的控制类
* @author Nicky
* @date 2017年3月7日
*/
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/articleSort")
public class ArticleSortAdminController extends BaseController{
......@@ -34,7 +35,7 @@ public class ArticleSortAdminController extends BaseController{
*/
@RequestMapping("/listAll")
public String listAllSort(Model model){
List<ArticleSort> articleSorts = articleSortService.findAll();
List<ArticleSortDto> articleSorts = articleSortService.findAll();
model.addAttribute("articleSorts", articleSorts);
return "myblog/index";
}
......@@ -46,7 +47,7 @@ public class ArticleSortAdminController extends BaseController{
*/
@RequestMapping("/labellist")
public String labelList(Model model){
List<ArticleSort> articleSorts = articleSortService.findAll();
List<ArticleSortDto> articleSorts = articleSortService.findAll();
model.addAttribute("articleSorts", articleSorts);
return "admin/label/label_list";
}
......@@ -58,13 +59,15 @@ public class ArticleSortAdminController extends BaseController{
@RequestMapping(value = "/listArticleCategory" ,method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
@ResponseBody
public String listArticleCategory() {
List<ArticleSort> categoryList = this.articleSortService.findAll();
List<ArticleSortDto> categoryList = this.articleSortService.findAll();
LOGGER.info("博客类别:{}"+categoryList.size());
//ObjectMapper mapper = new ObjectMapper();
/*JSONObject obj = new JSONObject();
for(ArticleSort a : categoryList) {
System.out.println(a.getName());
}
String result = JSONArray.toJSONString(categoryList);
obj.put("typeId", a.getTypeId());
obj.put("name", a.getName());
}*/
String result = JSON.toJSONString(categoryList, SerializerFeature.DisableCircularReferenceDetect);
return result;
}
......
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath %>">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Nicky's blog 写文章</title>
<link rel="icon" type="image/png" href="static/images/logo/logo.png">
<link href="<%=basePath %>plugins/editormd/css/editormd.min.css"
......@@ -40,7 +40,7 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
<header>
文章标题:<input type="text" id="articleTitle" />
类别:
<select id="articleCategory" onchange="javascript:categorySelect.init();"></select>
<select id="articleCategory"></select>
<span id="btnList">
<button type="button" id="publishArticle" class="btn btn-info">发布文章</button>
</span>
......@@ -104,7 +104,7 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
type: "GET",
url: 'articleSort/listArticleCategory.do',
dataType:'json',
//contentType:"application/json",
contentType:"application/json",
cache: false,
success: function(data){
//debugger;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册