CMS内容管理系统
站点:www.open1111.com
1.shiro 过滤请求做权限认证
/admin/**=authc 要权限才能访问, /login=anon 匿名访问。
    
    <!-- 自定义Realm ,登录的时候会用到此认证-->
    <bean id="myRealm" class="com.open1111.realm.MyRealm"/>  
    
    <!-- 安全管理器 -->
    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">  
        <property name="realm" ref="myRealm"/>  
    </bean>  
    
    <!-- Shiro过滤器 -->
    <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">  
        <!-- Shiro的核心安全接口,这个属性是必须的 -->  
        <property name="securityManager" ref="securityManager"/>
        <!-- 身份认证失败,则跳转到登录页面的配置 -->  
        <property name="loginUrl" value="/login.jsp"/> 
        <!-- Shiro连接约束配置,即过滤链的定义 -->  
        <property name="filterChainDefinitions">  
            <value>
                /login=anon
                /admin/**=authc
            </value>  
        </property>
    </bean>  
    
    <!-- 保证实现了Shiro内部lifecycle函数的bean执行 -->  
    <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>  
    
    <!-- 开启Shiro注解 -->
    <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor"/>  
    <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">  
          <property name="securityManager" ref="securityManager"/>  
       </bean>  
2.初始化组件
在web.xml中添加一个监听器,项目运行的时候加载一些数据。关键是allIndexArticleList 是一个大类别的集合(每个类别又包含此类的最新8条帖子),这样页面的遍历循环就
比较复杂(只贴出比较复杂的部分页面,其他见项目)。
<listener> <listener-class> com.open1111.service.impl.InitComponent </listener-class> </listener>
package com.open1111.service.impl; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; import com.open1111.entity.ArcType; import com.open1111.entity.Article; import com.open1111.entity.Link; import com.open1111.service.ArcTypeService; import com.open1111.service.ArticleService; import com.open1111.service.LinkService; /** * 初始化组件 * @author java1234_小锋 * */ @Component("initComponent") public class InitComponent implements ServletContextListener,ApplicationContextAware{ private static ApplicationContext applicationContext; public void refreshSystem(ServletContext application){ ArcTypeService arcTypeService=(ArcTypeService) applicationContext.getBean("arcTypeService"); List<ArcType> arcTypeList=arcTypeService.list(null); // 查询所有帖子类型 application.setAttribute("arcTypeList", arcTypeList); LinkService linkService=(LinkService) applicationContext.getBean("linkService"); // 查询所有友情链接 List<Link> linkList=linkService.list(null); application.setAttribute("linkList", linkList); ArticleService articleService=(ArticleService) applicationContext.getBean("articleService"); List<Article> newestArticleList=articleService.getNewest(); // 获取最新7条帖子 application.setAttribute("newestArticleList", newestArticleList); List<Article> recommendArticleList=articleService.getRecommend(); // 获取最新7条推荐的帖子 application.setAttribute("recommendArticleList", recommendArticleList); List<Article> slideArticleList=articleService.getSlide(); // 获取最新5条幻灯帖子 application.setAttribute("slideArticleList", slideArticleList); List allIndexArticleList=new ArrayList(); // 存储多个集合 每个集合是指定类别的最新8条帖子 if(arcTypeList!=null && arcTypeList.size()!=0){ for(int i=0;i<arcTypeList.size();i++){ List<Article> subArticleList=articleService.getIndex(arcTypeList.get(i).getId()); // 根据类别获取集合数据 allIndexArticleList.add(subArticleList); // 添加到总集合 } } application.setAttribute("allIndexArticleList", allIndexArticleList); } public void contextInitialized(ServletContextEvent servletContextEvent) { ServletContext application=servletContextEvent.getServletContext(); refreshSystem(application); } public void contextDestroyed(ServletContextEvent sce) { // TODO Auto-generated method stub } public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext=applicationContext; } }
<c:forEach var="allIndexArticle" items="${allIndexArticleList }" varStatus="allStatus"> <c:if test="${allStatus.index%3==0 }"> <!-- 0,3,6开始 --> <div class="w960 article_row"> </c:if> <c:forEach var="indexArticle" items="${allIndexArticle }" varStatus="oneStatus"> <c:if test="${oneStatus.first }"> <c:choose> <c:when test="${allStatus.index%3==0 }"> <div class="data_list article_list"> </c:when> <c:otherwise> <div class="data_list article_list" style="margin-left: 12px"> </c:otherwise> </c:choose> <div class="dataHeader">${arcTypeList.get(allStatus.index).typeName }<span class="more"><a href="${pageContext.request.contextPath}/arcType/${arcTypeList.get(allStatus.index).id }.html">更多...</a></span></div> <div class="datas"> <ul> </c:if> <li>[<fmt:formatDate value="${indexArticle.publishDate }" type="date" pattern="MM-dd"/>]  <a href="${pageContext.request.contextPath}/article/${indexArticle.id }.html" title="${indexArticle.title }"><font color="${indexArticle.titleColor }">${fn:substring(indexArticle.title,0,18) }</font></a></li> <c:if test="${oneStatus.last }"> </ul> </div> <!-- 对应 class="datas" --> </div> <!-- 对应 class="data_list article_list" --> </c:if> </c:forEach> <c:if test="${allStatus.index%3==2 || allStatus.last }"> <!-- 2,5,8结束class="w960 article_row" ,或者最后一个也是结束 --> </div> </c:if> </c:forEach>
3.使用百度站内搜索,所以不用想博客系统一样自己做全文索引。(需发布才能验证,还有留言系统是用搜狐畅言,QQ留言插件)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <div class="header_top"> <div class="w960"> <span class="time">Open1111 - 轻松建站赚钱从此开始</span> <div class="toplinks"> <form target="_blank"> [ <a target="_blank" href="http://shang.qq.com/wpa/qunwpa?idkey=5a688c5e4d85eaceb7b0354057daaba281d05191bb182776e5e65e7c46e03299">加入QQ群</a> ][ <a href="http://wpa.qq.com/msgrd?v=3&uin=527085608&site=qq&menu=yes" target="_blank">广告业务</a> ]  <input type="text" id="bdcsMain" class="search"/> <input type="submit" value="搜索"/> </form> </div> </div> </div> <script type="text/javascript">(function(){document.write(unescape('%3Cdiv id="bdcs"%3E%3C/div%3E'));var bdcs = document.createElement('script');bdcs.type = 'text/javascript';bdcs.async = true;bdcs.src = 'http://znsv.baidu.com/customer_search/api/js?sid=5738221493575509323' + '&plate_url=' + encodeURIComponent(window.location.href) + '&t=' + Math.ceil(new Date()/3600000);var s = document.getElementsByTagName('script')[0];s.parentNode.insertBefore(bdcs, s);})();</script> ================================================ <div> <!--PC版--> <div id="SOHUCS" sid="${article.id }"></div> <script charset="utf-8" type="text/javascript" src="http://changyan.sohu.com/upload/changyan.js" ></script> <script type="text/javascript"> window.changyan.api.config({ appid: 'cysGfqVIm', conf: 'prod_b63f4160d3c1165b9a6d353811cc8e2d' }); </script> </div>
文章编辑修改使用的是百度ueditor,加载相关内容要用 ue.addListener("ready",function(){ ...});
<script type="text/javascript">
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例,如果在某个闭包下引用该编辑器,直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');
    
    ue.addListener("ready",function(){
        //通过ajax请求数据
        UE.ajax.request("${pageContext.request.contextPath}/admin/article/findById.do",
            {
                method:"post",
                async : false,  
                data:{"id":"${param.id}"},
                onsuccess:function(result){
                    result = eval("(" + result.responseText + ")");  
                    $("#title").val(result.title);
                       $("#arcTypeId").combobox("setValue",result.arcType.id);
                       if(result.isSlide==1){
                           $("#isSlide").prop("checked",true);
                           $("#hdtp").show();
                       }
                       if(result.isRecommend==1){
                           $("#isRecommend").prop("checked",true);
                       }
                    $("#summary").val(result.summary);
                    $("#keyWords").val(result.keyWords);
                    $("#titleColor").val(result.titleColor);
                       UE.getEditor('editor').setContent(result.content);
                }
            }
        );
    });
    
     // 实例化colorPicker
     $("#bn").bigColorpicker("titleColor");
</script>
对于后面的value="1" 当时迷惑了, 选中checkbox值“1”才会传递到后台,否则传‘0’(model 中设置默认0),如果不写的话就会报错。比如考试系统 value="A",B,C,D 。
<input type="checkbox" id="isRecommend" name="isRecommend" value="1">推荐帖子
                    
                
                
            
        
浙公网安备 33010602011771号