说明

Blog实体类(博客实体)和BlogType实体类(博客类别实体),每个blog都有对应的blogType,博客类别实体有名称等属性,而我们只需要显示博客类别的名称,则格式化过程如下所示:

Java代码

Blog实体类:(博客实体,已省略setter和getter方法)

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
package com.ledao.entity;

import java.util.Date;

/**
* 博客实体
*
* @author LeDao
* @company
* @create 2020-09-11 00:08
*/
public class Blog {

/**
* id
*/
private Integer id;
/**
* 标题
*/
private String title;
/**
* 摘要
*/
private String summary;
/**
* 内容
*/
private String content;
/**
* 发布时间
*/
private Date releaseDate;
/**
* 点击次数
*/
private Integer click;
/**
* 博客类别id
*/
private Integer blogTypeId;
/**
* 博客类别
*/
private BlogType blogType;
/**
* 博客里存在的第一张图片,主要用于列表展示的缩略图
*/
private String imageName;
/**
* 博客数量 非博客实际属性 主要是 根据发布日期归档查询数量用到
*/
private Integer blogCount;
/**
* 发布日期的字符串 只取年和月
*/
private String releaseDateStr;
/**
* 该类型的博客数量
*/
private Integer blogNum;
/**
* 用于判断当前IP是否点赞过这篇博客
*/
private Integer isLike;
/**
* 点赞数
*/
private Integer likeNum;
/**
* 是否是导航条文章(0或空代表不是,1代表是)
*/
private Integer isMenuBlog;
/**
* 设置成为导航条文章的时间
*/
private Date setMenuBlogDate;

}

BlogType实体类:(博客类别实体,已省略setter和getter方法)

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
package com.ledao.entity;

/**
* 博客类别实体类
*
* @author LeDao
* @company
* @create 2020-09-10 21:22
*/
public class BlogType {

/**
* id
*/
private Integer id;
/**
* 博客类别名称
*/
private String name;
/**
* 排列数字
*/
private Integer sortNum;
/**
* 该类别的博客数量
*/
private Long blogNum;

}

HTML代码

1
2
3
4
5
6
7
8
9
10
11
12
13
<table id="dg" title="博客管理" class="easyui-datagrid" striped="true"
fitColumns="true" pagination="true" rownumbers="true"
url="/admin/blog/list" fit="true" toolbar="#tb">
<thead>
<tr>
<th field="cb" checkbox="true" align="center"></th>
<th field="id" width="20" align="center">编号</th>
<th field="title" width="200" align="center" formatter="formatTitle">标题</th>
<th field="releaseDate" width="50" align="center">发布日期</th>
<th field="blogType" width="50" align="center" formatter="formatType">博客类型</th>
</tr>
</thead>
</table>

JavaScript代码

1
2
3
function formatType(val, row) {
return val.name;
}