一. CMS

内容管理系统(Content Management System:内容管理系统,简称CMS)是一种位于WEB 前端(Web 服务器)和后端办公系统或流程(内容创作、编辑)之间的软件系统。内容的创作人员、编辑人员、发布人员使用内容管理系统来提交、修改、审批、发布内容。这里指的“内容”可能包括文件、表格、图片、数据库中的数据甚至视频等一切你想要发布到Internet、Intranet以及Extranet网站的信息。

二. CRM

客户关系管理系统(Customer Relationship Management),是指利用软件、硬件和[网络技术,为企业建立一个客户信息收集、管理、分析和利用的信息系统。以客户数据的管理为核心,记录企业在市场营销和销售过程中和客户发生的各种交互行为,以及各类有关活动的状态,提供各类数据模型,为后期的分析和决策提供支持。

三. GridManager—————快速、灵活的对Table标签进行实例化,让Table标签充满活力。

  1. 网址: http://gridmanager.lovejavascript.com

  2. 使用步骤:

    • 引入css和js

      1
      2
      3
      4
      <!-- 引入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>
    • html页面加上相应的table

      1
      <table id="table-demo-baseCode"></table>
    • js中配置查询

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      95
      96
      97
      98
      99
      100
      101
      102
      103
      104
      105
      106
      107
      108
      109
      110
      111
      112
      113
      114
      115
      116
      117
      118
      119
      120
      121
      122
      123
      124
      125
      126
      127
      128
      129
      130
      131
      132
      133
      134
      135
      136
      137
      $(function () {
      document.querySelector('#table-demo-ajaxPageCode').GM({
      //唯一组件标示
      gridManagerName: 'demo-ajaxPageCode',
      //ajax请求
      ajaxData: '/system/article/list', ajaxType: 'POST',
      //开启分页
      supportAjaxPage: true, supportAdjust: false, supportDrag: false,
      //表格数据
      height: '100%',
      currentPageKey: 'currentPage',
      pageSizeKey: 'pageSize',
      sizeData: [5, 10, 20, 50, 100, 150], //配置每页显示条数的下拉项,数组元素仅允许为正整数。
      pageSize: 10, //初次进行页面的每页条数(不写默认20)
      columnData: [{
      key: 'title', text: '文章标题', align: 'center', remind: 'the title'
      }, {
      key: 'url', text: '文章链接', align: 'center', remind: 'the link'
      }, {
      key: 'clickCount', text: '点击量', align: 'center', remind: 'the click'
      }, {
      key: 'articleType', text: '文章类型', align: 'center', remind: 'the type',
      template: function (cell, row, index, key) {
      return cell.name
      }
      }, {
      key: 'enable', text: '状态', align: 'center', remind: 'the status',
      //模板方法 自定义返回内容
      //cell:查询到的值,row:整行内容,index:索引,key:当前的key=enable
      template: function (cell, row, index, key) {
      return cell === true ? "<span style='color: green'>启用</span>" : "<span style='color: red'>禁用</span>"
      }
      }, {
      key: 'createDate', text: '发布时间', align: 'center', remind: 'the date'
      }, {
      key: 'id', text: '操作', align: 'center', remind: 'the action',
      template: function (cell, row, index, key) {
      return "<button type='button' class='btn btn-warning btn-sm edit' data-article='" + JSON.stringify(row) + "'><span class='glyphicon glyphicon-pencil'></span>修改</button> " +
      "<button type='button' class='btn btn-danger btn-sm del' data-id='" + row.id + "'><span class='glyphicon glyphicon-trash'></span>删除</button>";
      }
      },
      ]
      });

      // 查询条件事件
      $('#queryButton').click(function () {
      //返回表单的json对象
      var query = $('#queryForm').serializeObject();
      //表格插件复用
      /*
      * 更改在生成组件时所配置的参数query,执行后将会自动刷新表格数据。
      注意事项:
      1. 当query的key与分页及排序等字段冲突时将会被忽略
      2. query中的key与columnData.key相同时,该值将会替换columnData.filter.selected的值
      3. setQuery() 执行后会立即触发刷新操作
      4. 在此配置的query在分页事件触发时, 会以参数形式传递至pagingAfter(query)事件内
      5. setQuery方法中对query字段执行的操作是覆盖而不是合并, query参数位传递的任意值都会将原来的值覆盖.
      6. setQuery() 执行后不会清除已选中的数据,如需清除可以在callback中执行setCheckedData(table, [])

      GridManager.setQuery(table,{'userName':'baukh','sex':'男'}, gotoPage, callback);
      */
      GridManager.setQuery('demo-ajaxPageCode', query)
      });

      //删除事件
      $('#table-demo-ajaxPageCode').on('click', '.del', function () {
      //获取需要删除的id值
      var id = $(this).data('id');
      console.log(id)
      //打开删除模态框
      $('#del-dialog').modal('show');
      //取消绑定事件
      $('#confirm-del-btn').off('click');
      //确认删除请求
      $('#confirm-del-btn').click(function () {
      //隐藏模态框
      $('#del-dialog').modal('hide');
      $.get('/system/article/delete', {'id': id}, function (res) {
      if (res.success) {
      //刷新数据
      GridManager.refreshGrid('demo-ajaxPageCode', true);
      } else {
      alert('删除失败' + res.msg);
      }
      }, 'json');
      })

      });

      // 添加按钮事件
      $('#addButton').click(function () {
      //开启新增模态框
      $('#save-dialog').modal('show');
      //清除隐藏的id值
      $('#id').val('');
      //清空表单内容
      $('#save-form').resetForm();
      //给单选框设置默认选中 禁用
      $('#disable').prop('checked', true)
      });
      //确认添加
      $('#confirm-save-btn').click(function () {
      // 获取form表单的值 自动转换为json对象
      var saveData = $('#save-form').serializeObject();
      console.log(saveData);
      //发送Ajax请求
      $.ajax({
      url: '/system/article/save',
      data: saveData,
      type: 'POST',
      success: function (res) {
      if (res.success) {
      //隐藏模态框
      $('#save-dialog').modal('hide');
      //刷新数据
      GridManager.refreshGrid('demo-ajaxPageCode', true);
      // alert('添加数据成功哦······');
      } else {
      alert('添加数据失败······' + res.msg);
      }
      },
      dataType: 'json',
      async: true
      })
      });

      // 修改文章按钮 事件委托
      $('#table-demo-ajaxPageCode').on('click', '.edit', function () {
      //获取当前行数据
      var article = $(this).data('article');
      console.log(article);
      //为表单赋值
      $('#save-form').setForm(article);
      //开启模态框
      $('#save-dialog').modal('show')
      });
      });

四.代码

1. 分页参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.lqs.vo;

import lombok.Data;

/**
* 分页查询的参数内容
*/
@Data
public class PageParams {
/*
当前页数
*/
private Integer currentPage;
/*
当前也数据量
*/
private Integer pageSize;
/*
查询起始索引位置
*/
private Integer pageBegin;

/**
* 初始化pageBegin
*
* @return pageBegin
*/
public Integer getPageBegin() {
if (currentPage != null && pageSize != null) {
return (this.currentPage - 1) * this.pageSize;
}
return null;
}
}

2. 统一Ajax返回结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.lqs.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* 统一返回ajax的请求结果
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AjaxResult {
private Boolean success;
private String msg;

public AjaxResult(boolean success) {
this.success = success;
}

public static AjaxResult success() {
return new AjaxResult(true);
}

public static AjaxResult error(String msg) {
return new AjaxResult(false, msg);
}
}

3. 封装查询结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.lqs.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
* 封装一个查询结果类 使用GridManager组件
*
* @param <T> 泛型
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class QueryResult<T> {
/*
查询结果数量
*/
private Long totals;
/*
返回的数据类型和数据
*/
private List<T> data;
}

4. 查询文章参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.lqs.vo;

import lombok.*;

@EqualsAndHashCode(callSuper = true)//解决子类对象比较不一至问题
@Data//只对当前类生效
@NoArgsConstructor
@AllArgsConstructor
@ToString(callSuper = true)//@Data 注解生成的 toString 方法也只包含了子类自有属性。
public class ArticleParams extends PageParams {
/*
文章id
*/
private Long id;
/*
文章标题
*/
private String title;
/*
类型id
*/
private Long typeId;
/*
是否禁用
*/
private Integer enable;

/*
文章内容
*/
private String content;
}

5. SQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<sql id="articleQuery">
<where>
<if test="title != null and !''.equals(title)">
title like concat('%',#{title},'%')
</if>

<if test="typeId != null">
and typeId = #{typeId}
</if>
<if test="enable != null">
and enable = #{enable}
</if>
</where>
</sql>

<select id="getAllArticlesAndType" resultMap="articleMap">
select a.*, b.name, b.code
from t_article a
left join t_article_type b on a.typeId = b.id
<include refid="articleQuery"/>
<if test=" pageBegin != null and pageSize != null">
limit #{pageBegin},#{pageSize}
</if>
</select>

<select id="getTotals" resultType="java.lang.Long">
select count(*) from t_article
<include refid="articleQuery"/>
</select>

<select id="getArticleByType" resultType="com.lqs.domain.Article">
SELECT *
from t_article a
LEFT JOIN t_article_type b on a.typeId = b.id
WHERE b.`code` = #{code}
AND a.`enable` = 1
ORDER BY a.createDate DESC
LIMIT 0,8
</select>

6. pom

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.lqs</groupId>
<artifactId>cms</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>


<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.2.1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>

<dependency>
<groupId>apache-taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>


<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.5.RELEASE</version>
</dependency>

<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.3</version>
</dependency>

<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.0</version>
</dependency>
<!-- 数据库 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.27</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>


<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.4</version>
</dependency>

<!-- 日志 -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>

<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.4.1.Final</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<scope>compile</scope>
</dependency>
<!-- jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.10.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.12.6</version>
</dependency>


<!-- 工具包 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.5</version>
</dependency>
</dependencies>

<!-- <build>-->
<!-- <resources>-->
<!-- &lt;!&ndash; maven项目中src源代码下的xml等资源文件编译进classes文件夹,-->
<!-- 注意:如果没有这个,它会自动搜索resources下是否有mapper.xml文件,-->
<!-- 如果没有就会报org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.pet.mapper.PetMapper.selectByPrimaryKey&ndash;&gt;-->
<!-- <resource>-->
<!-- <directory>src/main/java</directory>-->
<!-- <includes>-->
<!-- <include>**/*.xml</include>-->
<!-- </includes>-->
<!-- </resource>-->

<!-- &lt;!&ndash;将resources目录下的配置文件编译进classes文件 &ndash;&gt;-->
<!-- <resource>-->
<!-- <directory>src/main/resources</directory>-->
<!-- </resource>-->
<!-- </resources>-->
<!-- </build>-->
</project>