JEECMS站群管理系统-- 自定义标签及使用自己创建的表的实现过程
2015-04-06 13:15
471 查看
下面是我自己定义的标签mycontent_list
首先,在数据库里创建了一个jc_mycontent的表,其中有id,title,content三个字段
其次,创建了一个实体类
……get set方法
}
接下来是配置hibernate中jc_mycontent表的配置文件
与数据库交互的持久层接口
持久层实现类
业务层接口
业务层实现类
标签类的抽象类,最主要的就是getData这个方法,以及绑定业务层,其中可以添加多种查询方法。可参考类AbstractContentDirective
自定义标签中最重要的类继承上边的抽象类
样式模板mycontent_list.html内容,里边可以自己添加一些样式,可参考\t\cms_sys_defined\style_list下样式文件
首页里加入如下代码
通过以上这些代码,可以实现将自己的表jc_mycontent中的数据查询并显示在页面上
首先,在数据库里创建了一个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站群管理系统-- 首页的加载过程
- 使用.net core ABP和Angular模板构建博客管理系统(实现自己的业务逻辑)
- JEECMS站群管理系统-- Jeecms安装过程
- JEECMS站群管理系统-- Jeecms安装过程
- 典型J2EE系统架构图,该图为了自己使用而创建,如有什么不当的地方还请高手们指正,谢谢!
- 业务审批过程分析与使用Sbo系统存储过程实现业务审批流程状态检索
- 使用系统存储过程实现的通用分页存储过程
- 使用 ipmitool 实现 Linux 系统下对服务器的 ipmi 管理
- 使用存储过程实现进销存系统中的先进先出算法(1)――数据库与存储过程设计
- 使用 SharePoint 创建内容管理系统
- 使用 XForms 和 Ruby on Rails 开发小型门诊管理系统,第 2 部分:实现患者信息 Xform
- SQL 使用系统存储过程实现的通用分页存储过程
- 使用 ipmi实现Linux系统下对服务器的管理
- 使用 XForms 和 Ruby on Rails 开发小型门诊管理系统,第 3 部分:实现护士和医生 Xform
- 用于参考的学生信息管理系统(数据库简单 可自己参考创建)
- Linux系统管理.Linux中软RAID的创建过程
- C_综合使用数组实现简单的学生成绩管理系统