CMS 是”Content Management System” 的缩写,意为” 内容管理系统”。 内容管理系统是企业信息化建设和电子政务的新宠,也是一个相对较新的市场。对于内容管理,业界还没有一个统一的定义,不同的机构有不同的理解。

自定义标签 [mycontent_list] 实现步骤:
创建 jc_mycontent 的表
-- Create table
create table JC_MYCONTENT
(
id NUMBER not null,
title VARCHAR2(),
content VARCHAR2()
)
tablespace CMS
pctfree
initrans
maxtrans
storage
(
initial 64K
minextents
maxextents unlimited
);
-- Create/Recreate primary, unique and foreign key constraints
alter table JC_MYCONTENT
add constraint PK_ID primary key (ID)
using index
tablespace CMS
pctfree
initrans
maxtrans ;
创建实体类
package com.jeecms.cms.entity.main; public class MyContent {
private Integer id;
private String title;
private String content; public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public String getContent() {
return content;
} public void setContent(String content) {
this.content = content;
} public MyContent(Integer id, String title, String content) {
super();
this.id = id;
this.title = title;
this.content = content;
} public MyContent() {
super();
} }
接下来是配置 hibernate 中 jc_mycontent 表的配置文件
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.jeecms.cms.entity.main">
<class name="MyContent" table="jc_mycontent">
<meta attribute="sync-DAO">false</meta>
<cache usage="read-write" />
<id name="id" type="java.lang.Integer" column="id">
<generator class="identity" />
</id>
<property name="title" column="title" type="java.lang.String"
not-null="true" />
<property name="content" column="content" type="java.lang.String"
not-null="true" />
</class>
</hibernate-mapping>
持久层接口
package com.jeecms.cms.dao.main; import java.util.List; import com.jeecms.cms.entity.main.MyContent; public interface MyContentDao {
public List<MyContent> getList();
}
持久层实现类
package com.jeecms.cms.dao.main.impl; import java.util.List; import org.springframework.stereotype.Repository; import com.jeecms.cms.dao.main.MyContentDao;
import com.jeecms.cms.entity.main.MyContent;
import com.jeecms.common.hibernate4.Finder;
import com.jeecms.common.hibernate4.HibernateBaseDao; @Repository
// 持久层
public class MyContentDaoImpl extends HibernateBaseDao<MyContent, Integer> implements MyContentDao {
@SuppressWarnings("unchecked")
public List<MyContent> getList() {
return find(byNothing());
} private Finder byNothing() {
Finder f = Finder.create();
f.append("from MyContent");// 可以在此处添加查询条件或者添加各种方法进行动态查询
f.setCacheable(true);
return f;
} @Override
protected Class<MyContent> getEntityClass() {
return MyContent.class;
}
}
业务层接口
package com.jeecms.cms.manager.main; import java.util.List; public interface MyContentMng {
public List getList();
}public interface MyContentMng {
public List getList();
}
业务层实现类
package com.jeecms.cms.manager.main.impl; import java.util.List; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import com.jeecms.cms.dao.main.MyContentDao;
import com.jeecms.cms.entity.main.MyContent;
import com.jeecms.cms.manager.main.MyContentMng;
import com.jeecms.cms.service.ContentListener; @Service
// ()业务层
@Transactional
public class MyContentMngImpl implements MyContentMng {
@Transactional(readOnly = true)
// 配置事务为只读
public List<MyContent> getList() {
return myContentDao.getList();
} private MyContentDao myContentDao; @Autowired
// 自动绑定
public void setMyContentDao(MyContentDao myContentDao) {
this.myContentDao = myContentDao;
} private List<ContentListener> listenerList; @Autowired
public void setListenerList(List<ContentListener> listenerList) {
this.listenerList = listenerList;
}
}
标签类的抽象类
最主要的就是 getData 这个方法,以及绑定业务层 (其中也可以添加多种查询方法,可参考类 AbstractContentDirective)。 package com.jeecms.cms.action.directive.abs; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import com.jeecms.cms.manager.main.MyContentMng; import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException; public abstract class AbstractMyContentDirective implements TemplateDirectiveModel {
protected Object getData(Map params, Environment env) throws TemplateException {
return myContentMng.getList();
} @Autowired
protected MyContentMng myContentMng;
}
标签工具类 DirectiveUtils 下定义输出参数: MYOUT_LIST
public static final String MYOUT_LIST = "mytag_list";
自定义标签中最重要的类继承上边的抽象类
package com.jeecms.cms.action.directive; import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import com.jeecms.cms.action.directive.abs.AbstractMyContentDirective;
import com.jeecms.cms.entity.main.MyContent; import static com.jeecms.common.web.freemarker.DirectiveUtils.MYOUT_LIST;
import com.jeecms.common.web.freemarker.DefaultObjectWrapperBuilderFactory;
import com.jeecms.common.web.freemarker.DirectiveUtils;
import com.jeecms.core.entity.CmsSite;
import com.jeecms.core.web.util.FrontUtils; import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel; public class MyContentListDirective extends AbstractMyContentDirective {
/**
* 模板名称
*/
public static final String TPL_NAME = "mycontent_list"; @SuppressWarnings("unchecked")
public void execute(Environment env, @SuppressWarnings("rawtypes") Map params,
TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException,
IOException {
// 获取站点
CmsSite site = FrontUtils.getSite(env);
// 获取内容列表
List<MyContent> list = getList(params, env);
Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params);
// OUT_LIST值为tag_list,将内容列表放入其中
paramWrap.put(MYOUT_LIST, DefaultObjectWrapperBuilderFactory.getDefaultObjectWrapper()
.wrap(list)); // 将params的值复制到variable中 Map<String, TemplateModel> origMap = DirectiveUtils.addParamsToVariable(env, paramWrap);
// 没有采用默认的模板,直接采用自己写的简单的模板(mycontent_list.html)
FrontUtils.includeTpl(TPL_NAME, site, params, env);
// 将variable中的params值移除
DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap);
} @SuppressWarnings("unchecked")
protected List<MyContent> getList(Map<String, TemplateModel> params, Environment env)
throws TemplateException {
return myContentMng.getList();
}
}
在 jeecms-context.xml 中声明标签
<bean id="cms_mycontent_list" class="com.jeecms.cms.action.directive.MyContentListDirective"/>
在 jeecms-context.xml 中注入 DAO
<bean id="myContentDao" class="com.jeecms.cms.dao.main.impl.MyContentDaoImpl"/>
在 jeecms-context.xml 中注入 Manager
<bean id="myContentMng" class="com.jeecms.cms.manager.main.impl.MyContentMngImpl"/>
配置文件 jeecms-servlet-front.xml 中有一段对标签的配置
jeecms.properties 中配置标签名
directive.cms_mycontent_list=cms_mycontent_list
新建模板
WEB-INF\t\cms\www\oa\tag 下新建模板 mycontent_list.html, 并加入如下代码 (里边也可以自己添加一些样式,可参考 WEB-INF\t\cms_sys_defined\style_list 下样式文件) [#list mytag_list as a]
<li>
<a href="${a.title}">"${a.content}"</a>
</li>
[/#list]
调用代码
[@cms_mycontent_list]
[#list mycontent_list as a]
<li>
<a href="${a.title}">"${a.content}"</a>
</li>
[/#list]
[/@cms_mycontent_list]
通过以上这些代码,实现将自己的表 jc_mycontent 中的数据查询并显示在页面上 本文作者: IIsKei
本文链接: http://www.iskei.cn/posts/25712.html
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!

CMS 是”Content Management System” 的缩写,意为” 内容管理系统”。 内容管理系统是企业信息化建设和电子政务的新宠,也是一个相对较新的市场。对于内容管理,业界还没有一个统一的定义,不同的机构有不同的理解。

自定义标签 [mycontent_list] 实现步骤:

创建 jc_mycontent 的表

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
-- Create table
create table JC_MYCONTENT
(
id NUMBER not null,
title VARCHAR2(250),
content VARCHAR2(250)
)
tablespace CMS
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
-- Create/Recreate primary, unique and foreign key constraints
alter table JC_MYCONTENT
add constraint PK_ID primary key (ID)
using index
tablespace CMS
pctfree 10
initrans 2
maxtrans 255;

创建实体类

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
package com.jeecms.cms.entity.main;

public class MyContent {
private Integer id;
private String title;
private String content; public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public String getContent() {
return content;
} public void setContent(String content) {
this.content = content;
} public MyContent(Integer id, String title, String content) {
super();
this.id = id;
this.title = title;
this.content = content;
} public MyContent() {
super();
} }

接下来是配置 hibernate 中 jc_mycontent 表的配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.jeecms.cms.entity.main">
<class name="MyContent" table="jc_mycontent">
<meta attribute="sync-DAO">false</meta>
<cache usage="read-write" />
<id name="id" type="java.lang.Integer" column="id">
<generator class="identity" />
</id>
<property name="title" column="title" type="java.lang.String"
not-null="true" />
<property name="content" column="content" type="java.lang.String"
not-null="true" />
</class>
</hibernate-mapping>

持久层接口

1
2
3
4
5
6
7
8
9
package com.jeecms.cms.dao.main;

import java.util.List;

import com.jeecms.cms.entity.main.MyContent;

public interface MyContentDao {
public List<MyContent> getList();
}

持久层实现类

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
package com.jeecms.cms.dao.main.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.jeecms.cms.dao.main.MyContentDao;
import com.jeecms.cms.entity.main.MyContent;
import com.jeecms.common.hibernate4.Finder;
import com.jeecms.common.hibernate4.HibernateBaseDao; @Repository
// 持久层
public class MyContentDaoImpl extends HibernateBaseDao<MyContent, Integer> implements MyContentDao {
@SuppressWarnings("unchecked")
public List<MyContent> getList() {
return find(byNothing());
} private Finder byNothing() {
Finder f = Finder.create();
f.append("from MyContent");// 可以在此处添加查询条件或者添加各种方法进行动态查询
f.setCacheable(true);
return f;
} @Override
protected Class<MyContent> getEntityClass() {
return MyContent.class;
}
}

业务层接口

1
2
3
4
5
6
7
8
9
package com.jeecms.cms.manager.main;

import java.util.List;

public interface MyContentMng {
public List getList();
}public interface MyContentMng {
public List getList();
}

业务层实现类

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
package com.jeecms.cms.manager.main.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import com.jeecms.cms.dao.main.MyContentDao;
import com.jeecms.cms.entity.main.MyContent;
import com.jeecms.cms.manager.main.MyContentMng;
import com.jeecms.cms.service.ContentListener; @Service
// ()业务层
@Transactional
public class MyContentMngImpl implements MyContentMng {
@Transactional(readOnly = true)
// 配置事务为只读
public List<MyContent> getList() {
return myContentDao.getList();
} private MyContentDao myContentDao; @Autowired
// 自动绑定
public void setMyContentDao(MyContentDao myContentDao) {
this.myContentDao = myContentDao;
} private List<ContentListener> listenerList; @Autowired
public void setListenerList(List<ContentListener> listenerList) {
this.listenerList = listenerList;
}
}

标签类的抽象类

最主要的就是 getData 这个方法,以及绑定业务层 (其中也可以添加多种查询方法,可参考类 AbstractContentDirective)。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.jeecms.cms.action.directive.abs;

import java.util.Map;

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

import com.jeecms.cms.manager.main.MyContentMng;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException; public abstract class AbstractMyContentDirective implements TemplateDirectiveModel {
protected Object getData(Map params, Environment env) throws TemplateException {
return myContentMng.getList();
} @Autowired
protected MyContentMng myContentMng;
}

标签工具类 DirectiveUtils 下定义输出参数: MYOUT_LIST

1
public static final String MYOUT_LIST = "mytag_list";

自定义标签中最重要的类继承上边的抽象类

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
package com.jeecms.cms.action.directive;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import com.jeecms.cms.action.directive.abs.AbstractMyContentDirective;
import com.jeecms.cms.entity.main.MyContent; import static com.jeecms.common.web.freemarker.DirectiveUtils.MYOUT_LIST;
import com.jeecms.common.web.freemarker.DefaultObjectWrapperBuilderFactory;
import com.jeecms.common.web.freemarker.DirectiveUtils;
import com.jeecms.core.entity.CmsSite;
import com.jeecms.core.web.util.FrontUtils; import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel; public class MyContentListDirective extends AbstractMyContentDirective {
/**
* 模板名称
*/
public static final String TPL_NAME = "mycontent_list"; @SuppressWarnings("unchecked")
public void execute(Environment env, @SuppressWarnings("rawtypes") Map params,
TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException,
IOException {
// 获取站点
CmsSite site = FrontUtils.getSite(env);
// 获取内容列表
List<MyContent> list = getList(params, env);
Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params);
// OUT_LIST值为tag_list,将内容列表放入其中
paramWrap.put(MYOUT_LIST, DefaultObjectWrapperBuilderFactory.getDefaultObjectWrapper()
.wrap(list)); // 将params的值复制到variable中 Map<String, TemplateModel> origMap = DirectiveUtils.addParamsToVariable(env, paramWrap);
// 没有采用默认的模板,直接采用自己写的简单的模板(mycontent_list.html)
FrontUtils.includeTpl(TPL_NAME, site, params, env);
// 将variable中的params值移除
DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap);
} @SuppressWarnings("unchecked")
protected List<MyContent> getList(Map<String, TemplateModel> params, Environment env)
throws TemplateException {
return myContentMng.getList();
}
}

在 jeecms-context.xml 中声明标签

1
<bean id="cms_mycontent_list" class="com.jeecms.cms.action.directive.MyContentListDirective"/>

在 jeecms-context.xml 中注入 DAO

1
<bean id="myContentDao" class="com.jeecms.cms.dao.main.impl.MyContentDaoImpl"/>

在 jeecms-context.xml 中注入 Manager

1
<bean id="myContentMng" class="com.jeecms.cms.manager.main.impl.MyContentMngImpl"/>

配置文件 jeecms-servlet-front.xml 中有一段对标签的配置

jeecms.properties 中配置标签名

1
directive.cms_mycontent_list=cms_mycontent_list

新建模板

WEB-INF\t\cms\www\oa\tag 下新建模板 mycontent_list.html, 并加入如下代码 (里边也可以自己添加一些样式,可参考 WEB-INF\t\cms_sys_defined\style_list 下样式文件)

1
2
3
4
5
[#list mytag_list as a]
<li>
<a href="${a.title}">"${a.content}"</a>
</li>
[/#list]

调用代码

1
2
3
4
5
6
7
[@cms_mycontent_list]
[#list mycontent_list as a]
<li>
<a href="${a.title}">"${a.content}"</a>
</li>
[/#list]
[/@cms_mycontent_list]

通过以上这些代码,实现将自己的表 jc_mycontent 中的数据查询并显示在页面上

相关文章
Donate comment here

打赏

JEECMS 自定义标签的更多相关文章

  1. JEECMS自定义标签

    查看JEECMS的源代码发现开发者版本还没有类似现成的统计标签,一种解决的办法是使用现有的JEECMS标签,像这样Struts( [@cms_content_list channel=id]${tag ...

  2. Jeecms自定义标签用法[单个内容]

    1.com.jeecms.cms.action.directive包下建立自己的标签类

  3. [原创]JEECMS 自定义标签调用广告版位下的所有广告(利用广告管理管理首页幻灯片)

    JEECMS自带的只有[@cms_advertising]标签,并且官方没有给文档,用法: [@cms_advertising id='3']             <img src=&quo ...

  4. JEECMS自定义标签开发步骤2

    JEECMS自带的只有[@cms_advertising]标签,并且官方没有给文档,用法: [@cms_advertising id='3']             <img src=&quo ...

  5. JEECMS自定义标签开发步骤

    JEECMS自带的只有[@cms_advertising]标签,并且官方没有给文档,用法: [@cms_advertising id='3']             <img src=&quo ...

  6. JEECMS站群管理系统-- 自定义标签及使用自己创建的表的实现过程

    下面是我自己定义的标签mycontent_list 首先,在数据库里创建了一个jc_mycontent的表,其中有id,title,content三个字段 其次,创建了一个实体类 public cla ...

  7. 自己动手编写JEECMS自定义栏目统计标签

    今天想在给Java客二级版面加入栏目文章统计效果,如下图, 查看JEECMS的源代码发现开发者版本还没有类似现成的统计标签,一种解决的办法是使用现有的JEECMS标签,像这样Struts( [@cms ...

  8. [JSP]自定义标签库taglib

    自定义标签的步骤 自定义标签的步骤大概有三步: 1.继承javax.servlet.jsp.tagext.*下提供的几个标签类,如Tag.TagSupport.BodyTagSupport.Simpl ...

  9. [Java] JSP笔记 - 自定义标签

    自定义标签的创建步骤: 自定义标签的四大功能: 自定义标签的类结构: 在 1.0 中呢, 可以将 <body-content> 的值设置为 JSP, 2.0中则不允许在自定义标签体中出现j ...

随机推荐

  1. The Preliminary Contest for ICPC Asia Xuzhou 2019 G. Colorful String 回文树

    签到提: 题意:求出每一个回文串的贡献 (贡献的计算就是回文串不同字符的个数) 题解: 用回文树直接暴力即可 回文树开一个数组cost[ ][26] 和val[ ] 数组: val[i]表示回文树上节 ...

  2. ELK日志分析系统(原创)

    一.简介 ELK由Elasticsearch.Logstash和Kibana三部分组件组成: Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引 ...

  3. duboo注解使用详解

    一.背景 随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行. 当越来越的的接口与实现类的增加后,duboo的xml配置会越来越多,为了防止 ...

  4. 一点响应式Web设计与实现思路

    摘要: 是否还在为你的应用程序适配PC端,移动端,平板而苦苦思索呢,是否在寻找如何一套代码适配多终端方式呢,是否希望快速上手实现你的跨终端应用程序呢,是的话,那就看过来吧,本文阐述响应式UI设计相关理 ...

  5. MySQL 05章_模糊查询和聚合函数

    在之前的查询都需要对查询的关机中进行“精确”.“完整”完整的输入才能查询相应的结果, 但在实际开发过程中,通常需要考虑用户可能不知道“精确”.“完整”的关键字, 那么就需要提供一种不太严格的查询方式, ...

  6. MySQL中查询所有数据库占用磁盘空间大小

    查询所有数据库占用磁盘空间大小的SQL语句: 复制代码 代码如下:select TABLE_SCHEMA, concat(truncate(sum(data_length)/1024/1024,2), ...

  7. vue cli3使用webpack4打包优化

    去掉console.log,以及开启gzip const CompressionPlugin = require('compression-webpack-plugin');//引入gzip压缩插件 ...

  8. dialogs打开对话框选定文件夹,getopenfilename获取文件名

    如果需要使用“打开”.“打印”等Excel内置对话框已经具有的功能,可以使用代码直接调用这些内置的对话框,如下面的代码所示. #001  Sub DialogOpen() #002      Appl ...

  9. K8S之WebApi部署

    转载声明 本文转自:ASP.NET Core on K8S学习初探(3)部署API到K8S 1.下载镜像 docker pull edisonsaonian/k8s-demo 因为是测试流程,直接把文 ...

  10. leetcode-212-单词搜索②

    题目描述: 第一次提交:(超出时间限制) class Solution: def findWords(self, board: List[List[str]], words: List[str]) - ...