From 38816bf61b13ae84442e6a423771b6764bafe393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=93=AD=E9=A3=9E?= Date: Mon, 4 Jul 2022 03:45:24 +0000 Subject: [PATCH] update src/main/java/net/mingsoft/cms/action/web/MCmsAction.java. --- .../mingsoft/cms/action/web/MCmsAction.java | 197 +----------------- 1 file changed, 1 insertion(+), 196 deletions(-) diff --git a/src/main/java/net/mingsoft/cms/action/web/MCmsAction.java b/src/main/java/net/mingsoft/cms/action/web/MCmsAction.java index ee35ebb7..dceeec13 100755 --- a/src/main/java/net/mingsoft/cms/action/web/MCmsAction.java +++ b/src/main/java/net/mingsoft/cms/action/web/MCmsAction.java @@ -105,202 +105,7 @@ public class MCmsAction extends net.mingsoft.cms.action.BaseAction { private String htmlDir; - /** - * 动态列表页 - */ - @GetMapping("/index.do") - @ResponseBody - public String index(HttpServletRequest req, HttpServletResponse resp) { - Map map = BasicUtil.assemblyRequestMap(); - map.forEach((k, v) -> { - map.put(k, v.toString().replaceAll("('|\"|\\\\)", "\\\\$1")); - }); - map.put(ParserUtil.URL, BasicUtil.getUrl()); - //动态解析 - map.put(ParserUtil.IS_DO, true); - //设置动态请求的模块路径 - map.put(ParserUtil.MODEL_NAME, "mcms"); - map.put(ParserUtil.HTML,htmlDir); - //解析后的内容 - String content = ""; - try { - //根据模板路径,参数生成 - content = ParserUtil.rendering(ParserUtil.INDEX + ParserUtil.HTM_SUFFIX, map); - } catch (TemplateNotFoundException e) { - e.printStackTrace(); - } catch (MalformedTemplateNameException e) { - e.printStackTrace(); - } catch (ParseException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return content; - } - - /** - * 动态列表页 - * - * @param req - * @param resp - */ - @ResponseBody - @GetMapping("/list.do") - public String list(HttpServletRequest req, HttpServletResponse resp) { - Map map = BasicUtil.assemblyRequestMap(); - map.forEach((k, v) -> { - map.put(k, v.toString().replaceAll("('|\"|\\\\)", "\\\\$1")); - }); - //获取栏目编号 - String typeId = BasicUtil.getString(ParserUtil.TYPE_ID); - int size = BasicUtil.getInt("size", 10); - ContentBean contentBean = new ContentBean(); - contentBean.setCategoryId(typeId); - //获取文章总数 - List columnArticles = contentBiz.queryIdsByCategoryIdForParser(contentBean); - //判断栏目下是否有文章 - if (columnArticles.size() == 0) { - return ""; - } - //设置分页类 - PageBean page = new PageBean(); - page.setPageNo(BasicUtil.getPageNo()); - int total = PageUtil.totalPage(columnArticles.size(), size); - map.put(ParserUtil.COLUMN, columnArticles.get(0)); - //获取总数 - page.setTotal(total); - - //设置栏目编号 - map.put(ParserUtil.TYPE_ID, typeId); - - map.put(ParserUtil.URL, BasicUtil.getUrl()); - map.put(ParserUtil.PAGE, page); - //动态解析 - map.put(ParserUtil.IS_DO, true); - //设置动态请求的模块路径 - map.put(ParserUtil.MODEL_NAME, "mcms"); - map.put(ParserUtil.HTML, htmlDir); - //解析后的内容 - String content = ""; - try { - //根据模板路径,参数生成 - content = ParserUtil.rendering(columnArticles.get(0).getCategoryListUrl(), map); - } catch (TemplateNotFoundException e) { - e.printStackTrace(); - } catch (MalformedTemplateNameException e) { - e.printStackTrace(); - } catch (ParseException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return content; - } - - /** - * 动态详情页 - */ - @GetMapping("/view.do") - @ResponseBody - public String view(String orderby, String order, HttpServletRequest req, HttpServletResponse resp) { - //参数文章编号 - ContentEntity article = contentBiz.getById(BasicUtil.getString(ParserUtil.ID)); - if (ObjectUtil.isNull(article)) { - throw new BusinessException(this.getResString("err.empty", this.getResString("id"))); - } - if (StringUtils.isNotBlank(order)) { - //防注入 - if (!order.toLowerCase().equals("asc") && !order.toLowerCase().equals("desc")) { - throw new BusinessException(this.getResString("err.error", this.getResString("order"))); - } - } - - orderby = orderby.replaceAll("('|\"|\\\\)", "\\\\$1"); - PageBean page = new PageBean(); - //用于详情上下页获取当前文章列表对应的分类,根据文章查询只能获取自身分类 - String typeId = BasicUtil.getString(ParserUtil.TYPE_ID, article.getCategoryId()); - //根据文章编号查询栏目详情模版 - CategoryEntity column = categoryBiz.getById(typeId); - //解析后的内容 - String content = ""; - Map map = BasicUtil.assemblyRequestMap(); - map.forEach((k, v) -> { - //sql注入过滤 - map.put(k, v.toString().replaceAll("('|\"|\\\\)", "\\\\$1")); - }); - //动态解析 - map.put(ParserUtil.IS_DO, true); - //设置栏目编号 - map.put(ParserUtil.TYPE_ID, typeId); - //设置动态请求的模块路径 - map.put(ParserUtil.MODEL_NAME, "mcms"); - map.put(ParserUtil.URL, BasicUtil.getUrl()); - map.put(ParserUtil.PAGE, page); - map.put(ParserUtil.ID, article.getId()); - map.put(ParserUtil.HTML,htmlDir); - - ContentBean contentBean = new ContentBean(); - contentBean.setCategoryId(String.valueOf(typeId)); - contentBean.setOrderBy(orderby); - contentBean.setOrder(order); - List articleIdList = contentBiz.queryIdsByCategoryIdForParser(contentBean); - Map contentModelMap = new HashMap(); - ModelEntity contentModel = null; - for (int artId = 0; artId < articleIdList.size(); ) { - //如果不是当前文章则跳过 - if (articleIdList.get(artId).getArticleId().equals(article.getId())) { - artId++; - continue; - } - // 文章的栏目路径 - String categoryParentId = articleIdList.get(artId).getId(); - if (StringUtils.isNotBlank(articleIdList.get(artId).getCategoryParentIds())) { - categoryParentId += ',' + articleIdList.get(artId).getCategoryParentIds(); - } - // 文章的栏目模型编号 - Integer columnContentModelId = articleIdList.get(artId).getMdiyModelId(); - Map parserParams = new HashMap(); - parserParams.put(ParserUtil.COLUMN, articleIdList.get(artId)); - // 判断当前栏目是否有自定义模型 - if (columnContentModelId != null && columnContentModelId > 0) { - // 通过当前栏目的模型编号获取,自定义模型表名 - if (contentModelMap.containsKey(columnContentModelId)) { - parserParams.put(ParserUtil.TABLE_NAME, contentModel.getModelTableName()); - } else { - // 通过栏目模型编号获取自定义模型实体 - contentModel = (ModelEntity) modelBiz.getEntity(columnContentModelId); - // 将自定义模型编号设置为key值 - contentModelMap.put(columnContentModelId, contentModel.getModelTableName()); - parserParams.put(ParserUtil.TABLE_NAME, contentModel.getModelTableName()); - } - } - // 第一篇文章没有上一篇 - if (artId > 0) { - CategoryBean preCaBean = articleIdList.get(artId - 1); - page.setPreId(preCaBean.getArticleId()); - } - // 最后一篇文章没有下一篇 - if (artId + 1 < articleIdList.size()) { - CategoryBean nextCaBean = articleIdList.get(artId + 1); - page.setNextId(nextCaBean.getArticleId()); - } - break; - } - try { - //根据模板路径,参数生成 - content = ParserUtil.rendering(column.getCategoryUrl(), map); - } catch (TemplateNotFoundException e) { - e.printStackTrace(); - } catch (MalformedTemplateNameException e) { - e.printStackTrace(); - } catch (ParseException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return content; - } - + /** * 实现前端页面的文章搜索