cms_文章管理

文章管理

文章管理前端页面

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

<%@ 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 //设置弹出框的层级及结构
});

/*
这是上传图片的修改
拷贝staticueditorjsplib中的jar包,然后放入webappWEB-INFlib
再引入项目,不然单图上传不成功webappstaticueditorjspconfig.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【页面静态化存放资源的位置】


原文地址:https://www.cnblogs.com/china10/p/14303809.html