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

public class MyContent {
private static final long serialVersionUID = 1L;
private Integer id;
private String title;
private String content;
public MyContent () {
super();
}

……get set方法
}
接下来是配置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>

与数据库交互的持久层接口

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

持久层实现类

@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;
}
}

业务层接口

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

业务层实现类

@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

public abstract class AbstractMyContentDirective implements TemplateDirectiveModel {
protected Object getData(Map<String, TemplateModel> params, Environment env)
throws TemplateException {
return myContentMng.getList();
}
@Autowired
protected MyContentMng myContentMng;
}

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

public class MyContentListDirective extends AbstractMyContentDirective {
/**
* 模板名称
*/
public static final String TPL_NAME = "mycontent_list";
@SuppressWarnings("unchecked")
public void execute(Environment env, 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, DEFAULT_WRAPPER.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);
}
protected List<MyContent> getList(Map<String, TemplateModel> params,
Environment env) throws TemplateException {
return myContentMng.getList();
}
}

样式模板mycontent_list.html内容,里边可以自己添加一些样式,可参考\t\cms_sys_defined\style_list下样式文件

[#list mytag_list as a]
<li><a href="${a.title}"><font color='blue'>"${a.content}"</font></a></li>
[/#list]

首页里加入如下代码

[@cms_mycontent_list]
<ul class="topnews">
</ul>
[/@cms_mycontent_list]

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

JEECMS站群管理系统-- 自定义标签及使用自己创建的表的实现过程的更多相关文章

  1. JEECMS站群管理系统-- Jeecms安装过程

    Jeecms是基于java技术研发的站群管理系统,稳定.安全.高效.跨平台.无限扩展是jeecms 的优点,系统支持mysql.oracle.sqlserver.db2等主流数据库. 轻松建设大规模网 ...

  2. JEECMS站群管理系统-- 标签使用和模板的制作

    1模板规划 1.1资源文件 资源文件就是网页中用到的图片.CSS.JS等元素,在CMS系统中所有的资源文件在网站的根目录中的 /res_base/所属网站定义资源目录/TEMPLEATE/WEB /r ...

  3. JEECMS站群管理系统-- 标签的配置流程

    以cms_content_list为例,首先,每一个标签的声明都是在jeecms-context.xml中进行的, <?xml version="1.0" encoding= ...

  4. JEECMS站群管理系统-- 首页的加载过程

    在浏览器中输入http://localhost:8080/jeecms,回车 首先进入配置文件web.xml, <context-param> <param-name>cont ...

  5. JEECMS站群管理系统-- Jeecms项目导入myeclipse

    1.在myeclipse中新建一个项目jeecms,将服务器中jeecms项目下web-inf文件夹下内容拷到新建项目中 解压缩jeecms-3.0.2-final-src,在src文件夹下会看到有三 ...

  6. CMSZU站群管理系统 升级到 v1.8 [源码下载]

    CmsZu 简介 CMSZU即CMS族,是个网站内容管理平台,基于PHP+MYSQL技术创建,源码开放. CmsZu 更新说明 V1.8 修改了些bug 完善数据库管理 -> 数据库表管理的 字 ...

  7. 原 jeecms9自定义标签以及使用新创建的数据库表

    转载地址:https://blog.csdn.net/nice_meng/article/details/89179089 本系统使用的是jeecmsv9版本,收集网上知识后,进行个人汇总 首先,自己 ...

  8. jeecms9自定义标签以及使用新创建的数据库表

    转载 https://blog.csdn.net/nice_meng/article/details/89179089 本系统使用的是jeecmsv9版本,收集网上知识后,进行个人汇总 首先,自己创建 ...

  9. JEECMS 自定义标签

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

随机推荐

  1. “网易大数据讲堂第一期:数说”直播活动资料:课程回放收看及PPT下载

    欢迎访问网易云社区,了解更多网易技术产品运营经验. "网易大数据讲堂第一期:数说"直播活动昨晚顺利举行.感谢各位"数"友的支持和参与. 本次活动PPT可点击这里 ...

  2. Nginx——1.基础知识

    Nginx——1.基础知识 作为高速.轻量.高性能等优点集于一身的服务器,Nginx在近些年迅速发展并不断扩大市场份额,甚至在最近其市场份额一举超过微软的IIS,跃身到第二位,仅次于Apache. 但 ...

  3. LINQ和Lambda表达式

    前言 前段时间接触了一种新的表达式,但是不知道这个是什么意思,所以就先站在巨人的肩膀用了,现在听师哥说这种写法是Lambda表达式.我一直以为,这个Lambda表达式和LINQ查询有异曲同工之妙,可惜 ...

  4. [A/C 2007] 数据备份(网络流,堆)

    [A/C 2007] 数据备份(网络流,堆) 给你N各点的位置和K条链,需要用这些链把2K个点连起来,使得链的总长最短.可以随意选择要链的点.n=100000. 这道题居然可以用堆-- 首先,不能把区 ...

  5. ABAP F4使用总结!!

    PARAMETERS: p_werks LIKE t001l-werks ,             p_lgort LIKE t001l-lgort . SELECTION-SCREEN SKIP. ...

  6. StampedLock原理

    原文链接:https://blog.csdn.net/sunhaoning/article/details/68924625 StamppedLock是Java 8中引入的一种新的锁机制.读写锁虽然分 ...

  7. 数据结构4:顺序表(线性表的顺序存储结构)及C语言实现

    逻辑结构上呈线性分布的数据元素在实际的物理存储结构中也同样相互之间紧挨着,这种存储结构称为线性表的顺序存储结构. 也就是说,逻辑上具有线性关系的数据按照前后的次序全部存储在一整块连续的内存空间中,之间 ...

  8. 在使用jquery时,(e.target).closest("li")是什么意思

    今天在群里有童鞋问以下代码中: $(function(){ $(document).bind("click", function (e) { $(e.target).closest ...

  9. eclipse gradle 找不到依赖解决办法

    右击工程,选择gradle  在点击Refresh Gradle Project 即可,..不得不说,gradle 在eclipse 下真没maven 好用.....

  10. Codeforces-C-Grid game(思维)

    You are given a 4x4 grid. You play a game - there is a sequence of tiles, each of them is either 2x1 ...