说明
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;
public class Blog {
private Integer id;
private String title;
private String summary;
private String content;
private Date releaseDate;
private Integer click;
private Integer blogTypeId;
private BlogType blogType;
private String imageName;
private Integer blogCount;
private String releaseDateStr;
private Integer blogNum;
private Integer isLike;
private Integer likeNum;
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;
public class BlogType {
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; }
|