Jeecms安裝過程
JDK5+TOMCAT5.5+MYSQL5 及以上,具體安裝過程請參考官方網站的圖文說明 (《JDK+TOMCAT+MYSQL 圖文安裝指南》,網址是http://www.jeecms.com/hjdj/760.htm )
將解壓後得到的jeecms-3.0.2-final檔案夾下的root檔案夾更名為jeecms拷貝到tomcat 安裝目錄下的webapps 檔案夾下(例如: D:\Tomcat 6.0\webapps\),啟動tomcat,在地址欄中輸入http://localhost:8080/jeecms, 您將看到第一步安裝過程中的《使用者許可協議》,勾選“我已經閱讀並同意此 協議”,點擊下一步, 接下來第二步安裝過程中設定系統參數,系統會自動檢測出一些配置項,請根據您的實際情 況填寫,資料庫密碼不可為空。 點擊提交後進入第三步進入最後的系統安裝過程,安裝過程可能需要十幾秒的等待時間。安
裝成功後將提示資訊,請再重啟Tomcat 完成安裝。
Tomcat重啟完畢之後,在瀏覽器的地址欄中輸入http://localhost:8080/jeecms,
若系統正常顯示預設的網站首頁則表示JEECMS 已經順利安裝完成.
附:
系統管理後台登入:http://localhost:8080/jeecms/jeeadmin/jeecms/index.do
使用者名稱:admin
密 碼:password
Jeecms項目匯入myeclipse
1.在myeclipse中建立一個項目jeecms,將伺服器中jeecms項目下web-inf檔案夾下內容拷到建立項目中
2.解壓縮jeecms-3.0.2-final-src,在src檔案夾下會看到有三個壓縮檔,如果只想進行普通的二次開發,可以只匯入cms這個源碼,刪除jeecms-cms-identity-3.0.2-final.jar即可,如果想進行深入的二次開發,需要匯入common和core源碼,另匯入common-lib下的jar包,刪除jeecms-cms- identity-3.0.2-final.jar,jeecms-common-3.0.2-final.jar ,jeecms-core- identity-3.0.2-final.jar這三個jar包,切記:務必進行build
path
3.修改jdbc連結,自己匯入資料庫。
4.把伺服器下install\config下的web.xml複製出來覆蓋掉建立項目WEB-INF下的web.xml
5.classes下有四個檔案,手動烤到myeclipse項目src根目錄下中
6.將伺服器上jeecms項目刪掉,發布建立的jeecms項目。
首頁的載入過程:
在瀏覽器中輸入http://localhost:8080/jeecms,斷行符號
首先進入設定檔web.xml,
<context-param>
< param-name>contextConfigLocation</param-name>
< !---->
<param-value>
/WEB-INF/config/application-context.xml
/WEB-INF/config/cache-context.xml
/WEB-INF/config/captcha-context.xml
/WEB-INF/config/jeecore-context.xml
/WEB-INF/config/jeecms-context.xml
< /param-value>
< /context-param>
應用範圍內的初始化參數
其中jeecms-context.xml是對標籤的初始化
<welcome-file-list>
< welcome-file>index.html</welcome-file>
< welcome-file>index.shtml</welcome-file>
< welcome-file>index.jhtml</welcome-file>
< /welcome-file-list>
通過以上標籤找到應該載入哪一個頁面
<servlet>
< servlet-name>JeeCmsFront</servlet-name>
< servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
< init-param>
< param-name>contextConfigLocation</param-name>
< param-value>/WEB-INF/config/jeecms-servlet-front.xml</param-value>
< /init-param>
< load-on-startup>2</load-on-startup>
< /servlet>
< servlet-mapping>
< servlet-name>JeeCmsFront</servlet-name>
< url-pattern>*.jhtml</url-pattern>
< /servlet-mapping>
< servlet-mapping>
< servlet-name>JeeCmsFront</servlet-name>
< url-pattern>*.jspx</url-pattern>
< /servlet-mapping>
< servlet-mapping>
< servlet-name>JeeCmsFront</servlet-name>
< url-pattern>*.jsp</url-pattern>
< /servlet-mapping>
< servlet-mapping>
< servlet-name>JeeCmsFront</servlet-name>
< url-pattern>*.htm</url-pattern>
< /servlet-mapping>
通過servlet配置,可以找到jeecms-servlet-front.xml,在此設定檔的最後有
<import resource="jeecms-servlet-front-action.xml"/>代碼
找到jeecms-servlet-front-action.xml,在此設定檔中有
<bean id="dynamicAct" class="com.jeecms.cms.action.front.DynamicPageAct"/>
可以找到類DynamicPageAct,此類是首頁模板。
在類DynamicPageAct中有
public static final String TPL_INDEX = "tpl.index";
找到WEB-INF\languages\jeecms_front下messages_zh_CN.properties設定檔,可以找到對應的首頁面
tpl.index=首頁(工程中的首頁.html檔案)
標籤的配置流程,以cms_content_list為例
首先,每一個標籤的聲明都是在jeecms-context.xml中進行的,
< ?xml version="1.0" encoding="UTF-8"?>
< beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
default-lazy-init="true">
……
<bean id="cms_content_list" class="com.jeecms.cms.action.directive.ContentListDirective"/>(聲明標籤對應的類)
<bean id="staticPageSvc" class="com.jeecms.cms.staticpage.StaticPageSvcImpl">
< property name="freeMarkerConfigurer">
< bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
< property name="freemarkerVariables">
< map>
……
<entry key="cms_content_list" value-ref="cms_content_list"/>
……
< /map>
< /property>
< property name="templateLoaderPath" value=""/>
……
< /bean>
< /property>
< /bean>
< /beans>
此外,在設定檔jeecms-servlet-front.xml中,還有一段對標籤的配置
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
< property name="freemarkerVariables">
< map>
……
<entry key="cms_content_list" value-ref="cms_content_list"/>
……
</map>
< /property>
……
< /bean>
< /bean>類ContentListDirective繼承自AbstractContentDirective,最主要的是execute方法
public class ContentListDirective extends AbstractContentDirective {
/**
* 模板名稱
*/
public static final String TPL_NAME = "content_list";
/**
* 輸入參數,文章ID。允許多個文章ID,用","分開。排斥其他所有篩選參數。
*/
public static final String PARAM_IDS = "ids";
@SuppressWarnings("unchecked")
public void execute(Environment env, Map params, TemplateModel[] loopVars,
TemplateDirectiveBody body) throws TemplateException, IOException {
//擷取網站
CmsSite site = FrontUtils.getSite(env);
//擷取內容列表,可以通過此處變更,擷取自己資料庫中的資料
List<Content> list = getList(params, env);
Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(
params);
//OUT_LIST值為tag_list,在類DirectiveUtils中聲明,將內容列表放入其中
paramWrap.put(OUT_LIST, DEFAULT_WRAPPER.wrap(list));
//將params的值複製到variable中
Map<String, TemplateModel> origMap = DirectiveUtils
.addParamsToVariable(env, paramWrap);
//擷取的是參數PARAM_TPL,是否調用模板以及調用的模板類型
InvokeType type = DirectiveUtils.getInvokeType(params);
//擷取傳入參數,列表樣式,根據不同的參數擷取不同的樣式列表
String listStyle = DirectiveUtils.getString(PARAM_STYLE_LIST, params);
if (InvokeType.sysDefined == type) {
if (StringUtils.isBlank(listStyle)) {
throw new ParamsRequiredException(PARAM_STYLE_LIST);
}
//列表樣式模板
env.include(TPL_STYLE_LIST + listStyle + TPL_SUFFIX, UTF8, true);
} else if (InvokeType.userDefined == type) {
if (StringUtils.isBlank(listStyle)) {
throw new ParamsRequiredException(PARAM_STYLE_LIST);
}
//列表樣式模板路徑 WEB-INF\t\cms_sys_defined\style_list\style_2-1.html
FrontUtils.includeTpl(TPL_STYLE_LIST, site, env);
} else if (InvokeType.custom == type) {
//這個模板就是自己聲明的,即content_list.html,如果採用自訂模板的話,頁面中可以唯寫上標籤,並添加上標籤內需要的幾個參數,不需要寫標籤體的內容,會去自動調用模板中的標籤體。
FrontUtils.includeTpl(TPL_NAME, site, params, env);
} else if (InvokeType.body == type) {
body.render(env.getOut());
} else {
throw new RuntimeException("invoke type not handled: " + type);
}
//將variable中的params值移除
DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap);
}
@SuppressWarnings("unchecked")
protected List<Content> getList(Map<String, TemplateModel> params,
Environment env) throws TemplateException {
Integer[] ids = DirectiveUtils.getIntArray(PARAM_IDS, params);
if (ids != null) {
//根據內容ID數組擷取文章列表
return contentMng.getListByIdsForTag(ids, getOrderBy(params));
} else {
return (List<Content>) super.getData(params, env);
}
}
@Override
protected boolean isPage() {
return false;
}
}
Content_list.html中的內容
[#list tag_list as a]
< li><a href="${a.url}" target="_blank">${a.title}</a></li>
[/#list]
就是簡單的將tag_list中的內容,即“paramWrap.put(OUT_LIST, DEFAULT_WRAPPER.wrap(list));”中放入的資料遍曆出來
style_2-1.html中的內容 主要是對圖文列表或標題列表向上滾動的樣式的,其中包含兩個同樣為樣式的檔案
style_2-1_core.html(圖文列表或標題列表向上滾動)和style_1-1_core.html(圖文列表或標題列表向上滾動),在此就不做贅述了。
Jeecms是基於Spring註解,在自訂標籤時對於實體類和dao service等注意註解的問題。
下面是我自己定義的標籤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中的資料查詢並顯示在頁面上