文章管理

文章管理前端页面

把引入的多个布局抽成了公共代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<title>CMS系统欢迎您</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Main CSS-->
<%@ include file="/WEB-INF/views/common/topStatic.jsp" %>


<!-- 富文本引用文件 -->
<!-- 配置文件 -->
<script type="text/javascript" src="/static/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/static/ueditor/ueditor.all.js"></script>




</head>
<body class="app sidebar-mini">
<!-- 导航条-->
<!-- Sidebar menu-->
<%@ include file="/WEB-INF/views/common/header.jsp" %>
<!-- 侧边栏 -->
<%@ include file="/WEB-INF/views/common/leftMenu.jsp" %>
<!-- 中间显示内容的 -->
<main class="app-content">
<!-- 列表展示 -->
<div class="row app-title">
<div class="col-md-12">


<!-- 删除模态框 -->
<div class="modal fade" id="delModal">
<div class="modal-dialog">
<div class="modal-content message_align">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h6 style="color: red">您确认要删除吗?</h6>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<a href="javascript:" id="delModelButton"
class="btn btn-success">确定</a>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>



<!-- 添加修改的模态框 -->
<div class="modal fade bs-example-modal-lg" id="saveModel">
<div class="modal-dialog modal-lg">
<div class="modal-content message_align">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="/system/article/save" method="post" class="form-horizontal" id="saveForm">
<input type="hidden" name="id" id="id">
<div class="form-group row">
<label for="title" class="control-label col-md-3">文章标题</label>
<div class="col-md-9">
<input class="form-control" type="text" name="title">
</div>
</div>
<div class="form-group row">
<label for="typeId" class="control-label col-md-3">文章类型</label>
<div class="col-md-9">
<select name="typeId" class="form-control">
<c:forEach items="${types}" var="t">
<option value="${t.id}">${t.name}</option>
</c:forEach>
</select>
</div>
</div>
<div class="form-group row">
<label for="enable" class="control-label col-md-3">是否启用</label>
<div class="col-md-9">
<div class="form-check">
<label class="form-check-label"> <input
class="form-check-input" type="radio" checked="checked"
id="enable" name="enable" value="1">启用
</label>
</div>
<div class="form-check">
<label class="form-check-label"> <input
class="form-check-input" type="radio" name="enable" value="0">禁用
</label>
</div>
</div>
</div>
<div class="form-group row">
<label for="content" class="control-label col-md-3">文章内容</label>
<div class="col-md-9">
<!-- <textarea class="form-control" style="resize: none" rows="4"
name="content"></textarea> -->
<!-- 富文本框 -->
<!-- 加载编辑器的容器 -->
<script id="container" name="content" type="text/plain">
这里写你的初始化内容
</script>
<script type="text/javascript">
var ue = UE.getEditor('container', {
/* 富文本框使用的工具栏 toolbars: [
['fullscreen', 'source', 'undo', 'redo', 'bold']
], */
autoHeightEnabled: true,
autoFloatEnabled: true
});

/* 避免工具栏会被富文本会工具弹窗被挡住 */
var ue = UE.getEditor('container',{
initialFrameHeight: '200', /* 自定义富文本的高度 */
zIndex: 8888 //设置弹出框的层级及结构
});

/*
这是上传图片的修改
拷贝static\ueditor\jsp\lib中的jar包,然后放入webapp\WEB-INF\lib
再引入项目,不然单图上传不成功webapp\static\ueditor\jsp\config.json"imagePathFormat":"/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}",
上传保存路径,可以自定义保存路径和文件名格式
*/

</script>

</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<a href='javascript:void(0);' id="saveButton" class="btn btn-success">确定</a>
</div>
</div>
</div>
</div>







<!-- 高级查询表单 -->
<form id="queryForm" class="form-inline">
<div class="form-group">
<label for="title">标题:</label>
<input type="text" class="form-control" name="title" id="title">
</div>
<div class="form-group" style="margin-left: 20px">
<label>文章类型:</label>
<select name="typeId" class="form-control" id="typeId">
<!-- 封装在model里面,通过el表达式可以取到 -->
<option value="">请选择</option>
<c:forEach items="${types }" var="t">
<option value="${t.id }">${t.name }</option>
<!-- 这里是通过后台动态获得 -->
</c:forEach>
</select>
</div>
<div class="form-group" style="margin-left: 20px">
<label>是否启用:</label>
<select name="enable" class="form-control" id="enable">
<option value="">请选择</option>
<option value="1">启用</option>
<option value="0">禁用</option>
</select>
</div>
<button type="button" id="queryButton" class="btn btn-success" style="margin-left: 20px">查询</button>
</form>
</div>
</div>



<!-- 存放table列表 -->
<table id='table-demo-ajaxPageCode'></table>

</div>
</div>
</main>
<!-- Essential javascripts for application to work-->
<script src="/static/system/js/jquery-3.3.1.min.js"></script>
<script src="/static/system/js/bootstrap.min.js"></script>
<script src="/static/system/js/main.js"></script>
<!-- The javascript plugin to display page loading on top-->
<script src="/static/system/js/plugins/pace.min.js"></script>

<%@ include file="/WEB-INF/views/common/bottomStatic.jsp" %>
<!-- 本页面的增删改查操作的js -->
<script type="text/javascript" src="/static/system/js/article/article.js"></script>
</body>
</html>

抽出去的布局

  • bottomStatic.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!-- Essential javascripts for application to work-->
<script src="/static/system/js/jquery-3.3.1.min.js"></script>
<script src="/static/system/js/popper.min.js"></script>
<script src="/static/system/js/bootstrap.min.js"></script>
<script src="/static/system/js/main.js"></script>
<!-- The javascript plugin to display page loading on top-->
<script src="/static/system/js/plugins/pace.min.js"></script>
<!-- Page specific javascripts-->
<script type="text/javascript" src="/static/system/js/plugins/chart.js"></script>
<script src="/static/system/js/jquery.jdirk.js"></script>
<script src="/static/system/js/jquery-form.js"></script>
<script src="/static/system/js/form-setForm.js"></script>

  • header.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<header class="app-header">
<a class="app-header__logo" href="index.html">源码时代</a> <a
class="app-sidebar__toggle" href="#" data-toggle="sidebar"
aria-label="Hide Sidebar"></a>
<!-- 导航条右边菜单-->
<ul class="app-nav">
<!-- 用户菜单-->
<li class="dropdown"><a class="app-nav__item" href="#"
data-toggle="dropdown" aria-label="Open Profile Menu"> <i
class="fa fa-user fa-lg"></i></a>
<ul class="dropdown-menu settings-menu dropdown-menu-right">
<li><a class="dropdown-item" href="/system/logout">
<i class="fa fa-sign-out fa-lg"></i> 退出
</a></li>
</ul></li>
</ul>
</header>

  • leftMenu.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<div class="app-sidebar__overlay" data-toggle="sidebar"></div>
<aside class="app-sidebar">
<div class="app-sidebar__user">
<img class="app-sidebar__user-avatar" width="48px" height="48px"
src="/upload/1610442774664.jpg" alt="User Image">
<div>
<p class="app-sidebar__user-name">${user.nickName}</p>
</div>
</div>
<ul class="app-menu">
<li><a class="app-menu__item" href="/system/article/index">
<i class="app-menu__icon fa fa-dashboard"></i> <span
class="app-menu__label">文章管理</span>
</a></li>
<li><a class="app-menu__item" href="/system/slide/index">
<i class="app-menu__icon fa fa-dashboard"></i> <span
class="app-menu__label">轮播管理</span>
</a></li>
<li><a class="app-menu__item" href="/system/faq/index">
<i class="app-menu__icon fa fa-dashboard"></i> <span
class="app-menu__label">常见问题管理</span>
</a></li>
<li><a class="app-menu__item" href="/system/feedbacks/index">
<i class="app-menu__icon fa fa-dashboard"></i> <span
class="app-menu__label">好评如潮管理</span>
</a></li>
</ul>
</aside>

  • topStatic.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!-- Main CSS-->
<link rel="stylesheet" type="text/css"
href="/static/system/css/main.css">
<!-- Font-icon css-->
<link rel="stylesheet" type="text/css"
href="/static/system/css/font-awesome.min.css">
<!-- 引入girdmanager的css -->
<link rel="stylesheet" href="/static/system/gridmanager/css/gm.css">
<!-- 引入gridmanager的js -->
<script type="text/javascript" src="/static/system/gridmanager/js/gm.js"></script>

引入增删改查操作的js

document.querySelector('#table-demo-ajaxPageCode').GM({
gridManagerName: 'demo-ajaxPageCode', //gridManager的名称
ajaxData: '/system/article/list', //请求路径 -自动发送的ajax请求
ajaxType: 'POST', //请求方法
supportAjaxPage: true, //是否支持分页
currentPageKey: "localPage", //当前页
pageSizeKey: "pageSize", //每页显示的条数
supportDrag: false, //禁止列的拖曳
sizeData: [5,10,15,20], //分页的选项
pageSize: 5, //默认每页显示多少条
height: '100%', //显示全部高度
columnData: [ //列的数据 -- 返回的json数据对应
{
key: 'title',
text: '文章标题',
align: 'center'
},{
key: 'type',
text: '文章类型',
align: 'center',
template: function(cell, row, index, key){
return cell.name;
}
},{
key: 'clickCount',
text: '点击次数',
align: 'center'
},{
key: 'createDate',
text: '创建时间',
align: 'center'
},{
key: 'enable',
text: '是否启用',
align: 'center',
//cell:当前key对应的值 ,row:当前行对象 ,index,当前对象的下标 ,key就是当前值
template: function(cell, row, index, key){
return cell?"<span style='color:green'>启用</span>":"<span style='color:red'>禁用</span>";
}
},{
key: 'id',
text: '操作 &emsp;<a href="javascript:;" id="add" style="color:green" class="addBtn">添加</a>',
align: 'center',
template: function(cell, row, index, key){
//将json对象转成json的字符串
var jsonStr = JSON.stringify(row);
//data-obj这个定义属性的方式,获取的使用data()就可以自动转换,有个要求,字符串必须是标准格式
return "<a href='javascript:;' style='color:blue' data-obj='"+jsonStr+"'>修改</a>&emsp;"
+'<a href="javascript:;" style="color:red" data-id="'+cell+'">删除</a>';
}
}
]
});

$(function(){//页面加载事件

//高级查询
$('#queryButton').on('click',function(){
//通过GridManager的setQuery将表单的数据传递到后台【会将分页的数据传递过去】
//这个方法发送的请求就是指定的GridManager的请求:/system/article/list
//手动:不方便维护
//var title = $("#title").val();
//自动:先导入jquery.jdirk.js ,然后引入【在jquery下引入】,然后调用方法
var jsonForm = $("#queryForm").serializeObject();
GridManager.setQuery('demo-ajaxPageCode',jsonForm);
});

//删除功能 -- 事件委托
$("#table-demo-ajaxPageCode").on('click','a[data-id]',function(){
//获取被删对象的id值
var id = $(this).data('id');
//弹出删除模态框 -- 复制模态框
$("#delModal").modal("show");
//清除所有的事件
$("#delModalButton").off();
//绑定单击事件
$("#delModelButton").on('click',function(){
$.ajax({
type: "POST", //请求方式
url: "/system/article/del", //请求地址
data: "id=" + id, //请求参数
dataType: "json", //指定服务器返回的数据类型,如果是字符串就不用写,如果是对象和集合就必须写,它会自动转成json对象,方便使用
success: function(msg){ //回调函数
if(msg.success){//删除成功
//1.关闭模态框
$("#delModal").modal("hide");
//2.刷新页面,参数是GridManager的 名称
GridManager.refreshGrid('demo-ajaxPageCode');
}else{//删除失败
//1.关闭模态框
$("#delModal").modal("hide");
//2.提示
alert(msg.msg);
}
}
});
});
});

//点击添加按钮弹出模态框
$("#table-demo-ajaxPageCode").on('click','#add',function(){
//操作:清空表单,因为添加和修改使用的是同一个模态框,添加数据之后点击取消,再点击添加或修改还是以前的数据,所有需要清空

$("#saveForm").get(0).reset();
//操作:清空表单时不会清除隐藏域id,这样在添加和修改时要出问题
$("#saveForm #id").val("");
/*添加清空富文本*/
var ue = UE.getEditor('container');
ue.ready(function() {
ue.setContent('');
});
//显示模态框
$("#saveModel").modal("show");
$("#saveButton").off();
$("#saveButton").on('click',function(){
//将表单中的数据【表单项必须有name属性值】以ajax异步的方式进行提交 //请求就是表单中action的属性值
$("#saveForm").ajaxSubmit({
success:function(msg){
//1.关闭模态框
$("#saveModel").modal("hide");
if(msg.success){
//2.刷新页面,参数是GridManager的 名称
GridManager.refreshGrid('demo-ajaxPageCode');
}else{//操作失败
alert(msg.msg);
}
}
});
});
});

//点击修改按钮弹出模态框
$("#table-demo-ajaxPageCode").on('click','a[data-obj]',function(){
//操作:清空表单,因为添加和修改使用的是同一个模态框,添加数据之后点击取消,再点击添加或修改还是以前的数据,所有需要清空
/* 操作:清空表单时不会清除隐藏域id,这样在添加和修改时要出问题
$("#saveForm #id").val(""); */
$("#saveForm").get(0).reset();
//1.获取到回显的数据
var jsonObj = $(this).data('obj'); //json对象
console.debug(jsonObj)
//2.设置到模态框的表单中
$("#saveForm").setForm(jsonObj); //做回显
/*修改按钮富文本编辑回显数据*/
/*添加清空富文本*/
var ue = UE.getEditor('container');
ue.ready(function() {
ue.setContent(jsonObj.content);
});

$("#saveModel").modal("show");
//点击添加和修改模态框的【确定】按钮绑定单击事件
$("#saveButton").on('click',function(){
//将表单中的数据【表单项必须有name属性值】以ajax异步的方式进行提交 //请求就是表单中action的属性值
$("#saveForm").ajaxSubmit({
success:function(msg){
//1.关闭模态框
$("#saveModal").modal("hide");
if(msg.success){
//2.刷新页面,参数是GridManager的 名称
GridManager.refreshGrid('demo-ajaxPageCode');
}else{//操作失败
//2.提示
alert(msg.msg);
}
}
});
});
});

});

前端控制器交给的页面控制的

package cn.itsource.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

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.ResponseBody;

import cn.itsource.domain.Article;
import cn.itsource.domain.ArticleType;
import cn.itsource.query.IArticleQuery;
import cn.itsource.service.IArtService;
import cn.itsource.service.IArticleTypeService;
import cn.itsource.util.AjaxResult;
import cn.itsource.util.PageBase;

/**
* @Title: Articlecontroller.java
* @Package:cn.itsource.controller
* @Description:(文章管理)
* @author:lon
* @date:2021年1月15日
* @version:V1.0
*/
@Controller
@RequestMapping("/system")
public class Articlecontroller {
@Autowired
private IArtService service;
@Autowired
private IArticleTypeService TypeService;
@RequestMapping("/article/list")
@ResponseBody
public PageBase<Article> list(IArticleQuery ArticleQuery){
return service.findall(ArticleQuery);
}
/*文章查询高级查询回显*/
@RequestMapping("/article/index")
public String index(Model model){
System.out.println("uu");
List<ArticleType> types = TypeService.findAll();
model.addAttribute("types", types);
return "article/article";
}

@RequestMapping("/article/del")
@ResponseBody
public AjaxResult delete(Long id){
System.out.println("1");
try {
System.out.println("2");
service.delete(id);
return new AjaxResult(true, "");
} catch (Exception e) {
System.out.println("3");
return new AjaxResult(false, "小老弟你不行呀");
}
}

@RequestMapping("/article/save")
@ResponseBody
public AjaxResult save(Article article,HttpServletRequest req){
System.out.println("保存方法");
try {
System.out.println("后台来了");
service.save(article,req);
return new AjaxResult(true,"");
} catch (Exception e) {
return new AjaxResult(false, "操作失败");
}
}
@RequestMapping("/index")
public String index(){
return "index";
}
}

接收参数用的实体类

package cn.itsource.query;

import cn.itsource.util.BaseQuery;

public class ArticleQuery extends BaseQuery{
private String title;
private Long typeId;
private Boolean enable;
@Override
public String toString() {
return "ArticleQuery [title=" + title + ", typeId=" + typeId + ", enable=" + enable + "]";
}
public ArticleQuery(String title, Long typeId, Boolean enable) {
super();
this.title = title;
this.typeId = typeId;
this.enable = enable;
}
public ArticleQuery() {
super();
// TODO Auto-generated constructor stub
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Long getTypeId() {
return typeId;
}
public void setTypeId(Long typeId) {
this.typeId = typeId;
}
public Boolean getEnable() {
return enable;
}
public void setEnable(Boolean enable) {
this.enable = enable;
}
}

分页实现都会继承该类接收gridmanger提交的参数

package cn.itsource.util;

/**
* @Title: BaseQuery.java
* @Package:cn.itsource.util
* @Description:(作用:分页查询的工具类,分页查询都需要继承该类方便实现分页参数的接收和传递 )
* @author:long
* @date:2021年1月15日
* @version:V1.0
*/
public class BaseQuery{
private Integer localPage=0;
private Integer pageSize=0;
public Integer getBegin(){
return (localPage-1)*pageSize;
}

public Integer getLocalPage() {
return localPage;
}
public void setLocalPage(Integer localPage) {
this.localPage = localPage;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
@Override
public String toString() {
return "BaseQuery [localPage=" + localPage + ", pageSize=" + pageSize + "]";
}
}

文章管理页面处理器调用的方法

package cn.itsource.service;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import cn.itsource.domain.Article;
import cn.itsource.query.IArticleQuery;
import cn.itsource.util.PageBase;

public interface IArtService {
PageBase<Article> findall(IArticleQuery query);
void del(Long id,HttpServletRequest req);
Map<String, List<Article>> findArticle();
void save(Article article,HttpServletRequest req);
void delete(Long id);
Article updateClick(String url);
}

文章管理页面处理器调用的抽象类的实现

package cn.itsource.service.impl;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.itsource.domain.Article;
import cn.itsource.domain.ArticleType;
import cn.itsource.mapper.Articlemapper;
import cn.itsource.mapper.Artictypelemapper;
import cn.itsource.query.IArticleQuery;
import cn.itsource.service.IArtService;
import cn.itsource.util.Constant;
import cn.itsource.util.FreeMarkerUtil;
import cn.itsource.util.PageBase;
@Service
public class ArtServiceimpl implements IArtService{

@Autowired
private Articlemapper mapper;
@Autowired
private Artictypelemapper typemapper;

/*查询*/
@Override
public PageBase<Article> findall(IArticleQuery query) {
/*查询文章总数量: 根据高级查询拿三个条件来决定*/
Integer totalsCount = mapper.findTotalCount(query);
/*按照分页条件查数据: 高级查询三条件加入进来*/
List<Article> list = mapper.findAll(query);
/*给每一个article对象的type属性赋值*/
for (Article article : list) {
Long id = article.getTypeId();
ArticleType type = typemapper.findbyid(id);
//System.out.println(type);
article.setType(type);
}
PageBase<Article> li = new PageBase<>(list, totalsCount);

return li;
}

/*删除*/
@Override
public void delete(Long id) {
System.out.println("文章管理执行了删除操作");
mapper.delete(id);
}

/*前台文章分栏查询*/
@Override
public Map<String, List<Article>> findArticle() {
Map<String, List<Article>> map= new HashMap<>();
/*查询技术文章*/
List<Article> technologys = mapper.findArticleByCode(Constant.TECHNOLOGY);
/*查询行业新闻*/
List<Article> industrys = mapper.findArticleByCode(Constant.INDUSTRY);
/*查询学科咨询*/
List<Article> subjects = mapper.findArticleByCode(Constant.SUBJECT);
map.put("technologys", technologys);
map.put("industrys", industrys);
map.put("subjects", subjects);
return map;
}

/*添加*/
@Override
public void save(Article article, HttpServletRequest req) {
String realPath = req.getServletContext().getRealPath("/static/template");
File file = new File(realPath);
if(!file.exists()){//如果文件夹不存在,就创建文件夹
file.mkdirs();
}
String url = FreeMarkerUtil.createFile(realPath, "article.ftl", article, ".html");
article.setUrl("/static/template/"+url);
if(article.getId()!=null){
Article oldArticle = mapper.findById(article.getId());//得到了数据库中旧的那条数据
String oldUrl = oldArticle.getUrl();// /static/template/1605176075312.html
//F:/workspace/PojOneSpace/Day47_cms03/src/main/webapp+
String real = req.getServletContext().getRealPath("/");
new File(real,oldUrl).delete();//删除旧的文件
mapper.update(article);
}else{
mapper.add(article);
}
}

/*删除*/
@Override
public void del(Long id, HttpServletRequest req) {
Article article = mapper.findOne(id);
mapper.del(id);
String realPath = req.getServletContext().getRealPath("/");
new File(realPath, article.getUrl()).delete();

}

/*点击次数处理*/
@Override
public Article updateClick(String oldurl) {
System.out.println(oldurl);
String url="/static/template/"+oldurl;
Article article = mapper.findByURL(url);
article.setClickCount(article.getClickCount()+1);
/*把数据库的点击数也要修改并且回显*/
mapper.update(article);
System.out.println(article);
return article;
}
}

文章管理实现类会调用的mapper

package cn.itsource.mapper;

import java.util.List;

import cn.itsource.domain.Article;
import cn.itsource.query.IArticleQuery;

public interface Articlemapper {
List<Article> findAll(IArticleQuery query);
Integer findTotalCount(IArticleQuery query);
void delete(Long id);
List<Article> findArticleByCode(String constant);
void add(Article article);
void update(Article article);
Article findOne(Long id);
void del(Long id);
Article findById(Long id);
Article findByURL(String url);
}

文章管理mapper映射文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--
这个Mapper的主要功能就是写sql
mapper:根
namespace:命令空间 (用来确定唯一)以前这个是可以不加的,现在必需加
namespace的值:接口的完全限定名
-->
<mapper namespace="cn.itsource.mapper.Articlemapper">

<!-- void update(Article article);修改 -->
<update id="update" parameterType="Article">
update t_article set url=#{url},clickCount=#{clickCount},title=#{title},typeId=#{typeId},enable=#{enable},content=#{content},createDate=#{createDate} where id=#{id}
</update>



<!-- void add(Article article);添加 -->
<insert id="add" parameterType="Article">
insert into t_article (title,typeId,enable,url,content,createDate)
values (#{title},#{typeId},#{enable},#{url},#{content},#{createDate})
</insert>

<!-- void delete(Long id);删除 -->
<delete id="delete">
delete from t_article where id=#{id}
</delete>



<select id="findTotalCount" resultType="int" parameterType="ArticleQuery">
select count(id) from t_article
<include refid="query"></include>
</select>

<!-- List<Article> findAll(ArticleQuery query); -->
<select id="findAll" resultType="Article" parameterType="ArticleQuery">
select * from t_article
<include refid="query"></include><!-- 先高级查询然后在分页 -->
limit #{begin},#{pageSize}
</select>
<sql id="query">
<where>
<if test="typeId != null">
and typeId = #{typeId}
</if>
<if test="enable != null">
and enable = #{enable}
</if>
<!-- test里面的写法是ognl表达式,trim()是ognl语法:去掉两端的空白 -->
<if test="title != null and '' != title.trim()">
<!-- concat是mysql的函数:用于拼接字符串的 -->
and title like concat('%',trim(#{title}),'%')
</if>
</where>
</sql>
<!-- Article findByURL(String url); 根据url查找Article-->
<select id="findByURL" resultType="article">
select * from t_Article where url=#{url}
</select>

<!-- List<Article> findArticleByCode(String constant); -->
<select id="findArticleByCode" resultType="article">
SELECT * FROM t_article t1
INNER JOIN t_article_type t2 on t1.typeId=t2.id
WHERE t1.`enable`=1 and t2.code=#{constant}
ORDER BY t1.createDate desc
LIMIT 0,8
</select>
<!--Article findById(Long id);-->
<select id="findById" parameterType="long" resultType="article">
select * from t_article where id = #{id}
</select>
<!-- Article findOne(Long id); -->
<select id="findOne" parameterType="long" resultType="article">
select * from t_article where id = #{id}
</select>
</mapper>

功能模块:

后台高级查询,后台crud,添加运用到freemark

业务流程:

项目资源布局:

webapp根目录
页面:
|--home【前台首页 -- 页面】
|--WEB-INF/views【后台管理页面】
|--index.jsp【后台首页】
|--article【文章模块页面】
|--slide【轮播图模块页面】
|--common【后台共用页面】
上传的图片:
|--upload【后台轮播图上传 -- 上传图片】
|--ueditor【后台管理页面 -- 富文本上传的图片默认上传到这里】
静态资源:
|--static【前台和后台所有的静态资源】
|--home【前台首页 -- 静态资源js,css,img】
|--system【后台管理页面 -- 静态资源css,fonts,js,images】
|--gridmanager【后台数据列表用到的插件资源 -- css,js】
|--ueditor【富文本编辑器静载资源】
|--template【页面静态化存放资源的位置】

cms_文章管理的更多相关文章

  1. ASP.NET MVC5 网站开发实践(二) Member区域 - 文章管理架构

    上次把member的用户部分完成,现在开始做文章管理部分.文章部分根据涉及显示现实文章列表,发布文章,修改文章,删除文章等功能.最终的实现目标是使用权限来控制用户是否能进行相应操作,管理员权限的会显示 ...

  2. PHP文章管理

    功能说明:  文章的基本操作:添加,修改,锁定,解锁,推荐,删除等待  并有强大功能的搜索,评论,推荐给朋友等功能,并对安全性进行着重加强,漂亮的界面人性化的设计.  主要文件列表:  setup.p ...

  3. PHPCMS v9在后台文章管理列表添加类别

    进入PHPCMS v9后台—内容,进入PHPCMS的文章管理列表,要实现在文章标题前显示文章类别,就是可以直接在文章列表里看到类别,不需要点击进入编辑页面才可以看到,如下图: PHPCMS v9在后台 ...

  4. Java EE 学习(9):IDEA + maven + spring 搭建 web(5)- 博客文章管理

    转载:Gaussic(一个致力于AI研究却不得不兼顾项目的研究生) . 注:在阅读本文前,请先阅读: Java EE 学习(5):IDEA + maven + spring 搭建 web(1) Jav ...

  5. 使用IntelliJ IDEA开发SpringMVC网站(五)博客文章管理

    原文:使用IntelliJ IDEA开发SpringMVC网站(五)博客文章管理 摘要 通过对博客文章的管理,实现外键操作. 目录[-] 八.博客文章管理 1.查看文章 2.添加博客        3 ...

  6. 用 Flask 来写个轻博客 (30) — 使用 Flask-Admin 增强文章管理功能

    Blog 项目源码:https://github.com/JmilkFan/JmilkFan-s-Blog 目录 目录 前文列表 扩展阅读 实现文章管理功能 实现效果 前文列表 用 Flask 来写个 ...

  7. ASP.NET MVC 实现页落网资源分享网站+充值管理+后台管理(8)之文章管理

    到这一步,我们整个项目的核心搭建已经算是完成了,接下来就是我们业务功能的实际应用,也就是表现层的设计和实现,如果你是一个项目负责人,到这一步,接下来的工作就可以交给下面的兄弟去完成了,在这里我们用文章 ...

  8. PHP文章管理(2)

    ##############index.php######################  <?session_start();  require"./inc/func.php&qu ...

  9. Laravel建站04--建立后台文章管理

    路由配置 Route::group(['middleware' => 'auth', 'namespace' => 'Admin', 'prefix' => 'admin'], fu ...

随机推荐

  1. [LeetCode]367. Valid Perfect Square判断完全平方数

    方法有很多,我觉得比较容易记住的是两个,一个是二分法,在1-num/2中寻找目标数 另一个是数学方法: public boolean isPerfectSquare(int num) { /* 有很多 ...

  2. Java学习日报7.22

    //3.2   逆向输出三位整数!    7.22 package 三个和尚比身高1; import java.util.Scanner; public class Demo1{ @SuppressW ...

  3. Spring Cloud是什么鬼?

    研究了一段时间Spring Boot了准备向Spring Cloud进发,公司架构和项目也全面拥抱了Spring Cloud.在使用了一段时间后发现Spring Cloud从技术架构上降低了对大型系统 ...

  4. Thread.join详解

    /** * 如果某个线程在另一个线程t上调用t.join:那么此线程将被挂起,直到目标t线程的结束才恢复即t.isAlive返回为假 * * @date:2018年6月27日 * @author:zh ...

  5. Modbus 仿真测试工具 Mod_Rssim 详细图文教程

    Mod_RSsim是一款轻量级的Modbus从机模拟器,它可以模拟ModBusTCP和ModBusRTU的从机,能够同时模拟254个被控站,软件使用简单方便,可以满足一般的主机调试. 官方网站:www ...

  6. ContactCollections Design Report

    通讯录的设计采用了分层+接口+面向对象+文件操作+方法实现 分三层实现,共使用了四个包,实现业务数据访问和界面的分离     contactaccess包实现对文件的访问         包括数据访问 ...

  7. Web Service 服务无法连接Oracle数据库

    这个问题之前部署就遇到过,但是后来忘了,所以记录一下吧. 我部署Web Service服务的时候,服务没法正常运行,与Oracle数据库无法正常通信. 检查了数据库连接字没有任何问题,写了个测试接口, ...

  8. 服务器报错"您的主机中的软件中止了一个已建立的连接"

    网上很多的说法都模棱两可,只是说和远程连接有关,这个说的太泛泛了. 我现在遇到的问题是java web出现的, 执行表单提交的时候出现该错误,原因是ajax和表单同时提交导致的, 相信很多朋友用了aj ...

  9. linux网关服务器

    问题 多台服务器在内网网段,其中只有一台有公网ip可以上外网,需要让所有服务器都能连接外网 解决思路 使用路由转发的方式,将拥有公网ip的服务器搭建为网关服务器,即作为统一的公网出口 所谓转发即当主机 ...

  10. Linux—curl命令讲解

    命令:curl 在Linux中curl是一个利用URL规则在命令行下工作的文件传输工具,可以说是一款很强大的http命令行工具.它支持文件的上传和下载,是综合传输工具,但按传统,习惯称url为下载工具 ...