欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

JEECMS站群管理系統(tǒng)-- 自定義標(biāo)簽及使用自己創(chuàng)

系統(tǒng) 3027 0

下面是我自己定義的標(biāo)簽mycontent_list
首先,在數(shù)據(jù)庫里創(chuàng)建了一個(gè)jc_mycontent的表,其中有id,title,content三個(gè)字段
其次,創(chuàng)建了一個(gè)實(shí)體類

      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> 
    

與數(shù)據(jù)庫交互的持久層接口

      public interface MyContentDao { 

public List<MyContent> getList(); 

} 
    

持久層實(shí)現(xiàn)類

      @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");//可以在此處添加查詢條件或者添加各種方法進(jìn)行動態(tài)查詢 

f.setCacheable(true); 

return f; 

} 



@Override 

protected Class<MyContent> getEntityClass() { 

return MyContent.class; 

} 

} 
    


業(yè)務(wù)層接口

      public interface MyContentMng { 

public List<MyContent> getList(); 

} 
    

業(yè)務(wù)層實(shí)現(xiàn)類

      @Service//業(yè)務(wù)層 

@Transactional 

public class MyContentMngImpl implements MyContentMng { 



@Transactional(readOnly = true)//配置事務(wù)為只讀 

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; 

} 

} 
    


標(biāo)簽類的抽象類,最主要的就是getData這個(gè)方法,以及綁定業(yè)務(wù)層,其中可以添加多種查詢方法。可參考類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; 

} 
    

自定義標(biāo)簽中最重要的類繼承上邊的抽象類

      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 { 

//獲取站點(diǎn) 

CmsSite site = FrontUtils.getSite(env); 

//獲取內(nèi)容列表 

List<MyContent> list = getList(params, env); 

Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params); 

//OUT_LIST值為tag_list,將內(nèi)容列表放入其中 

paramWrap.put(MYOUT_LIST, DEFAULT_WRAPPER.wrap(list)); 

//將params的值復(fù)制到variable中 

Map<String, TemplateModel> origMap = DirectiveUtils.addParamsToVariable(env, paramWrap); 

//沒有采用默認(rèn)的模板,直接采用自己寫的簡單的模板(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內(nèi)容,里邊可以自己添加一些樣式,可參考\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] 
    

通過以上這些代碼,可以實(shí)現(xiàn)將自己的表jc_mycontent中的數(shù)據(jù)查詢并顯示在頁面上

JEECMS站群管理系統(tǒng)-- 自定義標(biāo)簽及使用自己創(chuàng)建的表的實(shí)現(xiàn)過程


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 草操影院| 亚洲特一级毛片 | 成人激情视频在线观看 | 成人欧美一级毛片免费观看 | 欧美日韩国产一区二区三区 | 成人18网站 | 91在线观| 鲁一鲁影院 | 婷婷色爱区综合五月激情韩国 | xxxx日本性 | yy4138理论片在线大全 | 欧美精品成人一区二区三区四区 | 狠狠久| 欧美一级色片 | 欧美亚洲精品一区 | 国产欧美一区二区三区免费看 | 日韩欧美视频一区二区在线观看 | 久久影城 | 日韩欧美国产偷亚洲清高 | 国产精品自拍99 | 午夜影院在线看 | 欧美13videosex性极品 | 黑人狂躁日本妞无码A片 | 色94色 成人| 99在线精品视频免费观里 | 久久99精品视频 | 亚洲人人 | 日韩成人在线电影 | 亚洲一区二区三区深夜天堂 | 国产综合视频在线 | 片一级片在线观看 | 日韩中文字幕一区 | 国产小视频在线观看www | 午夜精品久久久久久久99黑人 | 久久精品免费国产 | 久久精品二区 | 精品国产一区探花在线观看 | 天天舔天天射天天操 | 日韩欧美精品在线 | 亚洲欧美成人综合在线 | 999精品嫩草久久久久久99 |