JEECMS站群管理系统-- 自定义标签及使用自己创建的表的实现过程
下面是我自己定义的标签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站群管理系统-- 自定义标签及使用自己创建的表的实现过程的更多相关文章
- JEECMS站群管理系统-- Jeecms安装过程
Jeecms是基于java技术研发的站群管理系统,稳定.安全.高效.跨平台.无限扩展是jeecms 的优点,系统支持mysql.oracle.sqlserver.db2等主流数据库. 轻松建设大规模网 ...
- JEECMS站群管理系统-- 标签使用和模板的制作
1模板规划 1.1资源文件 资源文件就是网页中用到的图片.CSS.JS等元素,在CMS系统中所有的资源文件在网站的根目录中的 /res_base/所属网站定义资源目录/TEMPLEATE/WEB /r ...
- JEECMS站群管理系统-- 标签的配置流程
以cms_content_list为例,首先,每一个标签的声明都是在jeecms-context.xml中进行的, <?xml version="1.0" encoding= ...
- JEECMS站群管理系统-- 首页的加载过程
在浏览器中输入http://localhost:8080/jeecms,回车 首先进入配置文件web.xml, <context-param> <param-name>cont ...
- JEECMS站群管理系统-- Jeecms项目导入myeclipse
1.在myeclipse中新建一个项目jeecms,将服务器中jeecms项目下web-inf文件夹下内容拷到新建项目中 解压缩jeecms-3.0.2-final-src,在src文件夹下会看到有三 ...
- CMSZU站群管理系统 升级到 v1.8 [源码下载]
CmsZu 简介 CMSZU即CMS族,是个网站内容管理平台,基于PHP+MYSQL技术创建,源码开放. CmsZu 更新说明 V1.8 修改了些bug 完善数据库管理 -> 数据库表管理的 字 ...
- 原 jeecms9自定义标签以及使用新创建的数据库表
转载地址:https://blog.csdn.net/nice_meng/article/details/89179089 本系统使用的是jeecmsv9版本,收集网上知识后,进行个人汇总 首先,自己 ...
- jeecms9自定义标签以及使用新创建的数据库表
转载 https://blog.csdn.net/nice_meng/article/details/89179089 本系统使用的是jeecmsv9版本,收集网上知识后,进行个人汇总 首先,自己创建 ...
- JEECMS 自定义标签
CMS 是”Content Management System” 的缩写,意为” 内容管理系统”. 内容管理系统是企业信息化建设和电子政务的新宠,也是一个相对较新的市场.对于内容管理,业界还没有一个统 ...
随机推荐
- [raspberry pi3] raspberry 充当time machine
之前是用硬盘直接当timemachine的,看到有人用raspberry+硬盘充当timemachine的 自己的也搞了下,还是蛮方便的,下面是具体的步骤 1.安装必要的服务 sudo apt-get ...
- java 获取前几天时间
java 获取前几天时间 一.toLocaleString()函数过时: //当前时间 Date endDate=new Date(); String endTime=endDate.to ...
- 使用hexo搭建博客并上传GitHub
之前在博客园.简书.CSDN等地儿都开过博,一篇文章写好了,我希望能在几个平台可以同步发布,可是操作起来成本不低.几个平台下的富文本编辑器比较起来还是博客园更顺手,看着更舒服,尤其是代码块的操作灵活. ...
- 读《JavaScript权威指南》笔记(五)
1.getComputedStyle()方法的返回值是一个CSSStyleDeclaration对象,它代表了应用在指定元素(或伪对象)上的所有样式. 2.clip style="clip: ...
- 基于vue框架项目开发过程中遇到的问题总结(一)
(一)关于computed修改data里变量的值 问题:computed里是不能直接修改data里变量的值,否则在git commit 时会报错 解决:在computed里使用get和set来进行获取 ...
- the ssl module in Python is not available错误解决
在使用pip安装pymongo的过程中报错,提示如下: $ pip3 install pymongo pip is configured with locations that require TLS ...
- 第一次接触C++------感触
2018/09/24 上大学第一次接触C++,感觉还挺有趣的. C语言是计算机的一门语言,顾名思义,语言嘛,有它自己独特的语法. 第一次用C++敲代码,觉得还挺不错的,可以从中找到乐趣.咏梅老师布置的 ...
- dedecms图片绝对路径(附件绑定域名)的设置方法
dedecms默认的附件路径使用的是相对路径,但是在实际应用,我们可能会需要让文章的图片附件显示绝对地址,解决方案如下: 1.打开include目录下的文件extend.func.php,添加函数re ...
- luogu2723 丑数
提供一种单调队列做法(非正解) 显然每一个丑数能够由一个质数乘以另一个丑数得到 所以我们开k个单调递增队列,每次从这些队列顶部找到一个最小的元素把他捞出来,然后枚举所有质数,用这个元素乘以质数,放入相 ...
- redis数据库介绍(NoSql数据库)