主题 : 生成首页时报错
级别: 秀才
UID: 20792
积分:90 加为好友
威望: 0 精华: 0
主题:9 回复:37
注册时间:2011-06-15
在线时长:0
1#   发表于:2011-07-13 13:36:48  IP:218.6.*.*
 首页.html cms_mycontent_list not found.找不到标签
级别: 总版主
UID: 10736
积分:149787 加为好友
威望: 212 精华: 42
主题:297 回复:127674
注册时间:2010-09-08
在线时长:90.1
2#   发表于:2011-07-13 13:37:41  IP:115.170.*.*
首页模版修改过?
路漫漫其修远兮,吾将上下而求索!
级别: 秀才
UID: 20792
积分:90 加为好友
威望: 0 精华: 0
主题:9 回复:37
注册时间:2011-06-15
在线时长:0
3#   发表于:2011-07-13 13:50:19  IP:218.6.*.*
按照最顶文档,添加的

下面是我自己定义的标签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中的数据查询并显示在页面上
级别: 总版主
UID: 10736
积分:149787 加为好友
威望: 212 精华: 42
主题:297 回复:127674
注册时间:2010-09-08
在线时长:90.1
4#   发表于:2011-07-13 13:58:03  IP:115.170.*.*
现在就看是不是首页报错了,如果没报错,静态化即可生成
路漫漫其修远兮,吾将上下而求索!
1 共1页