为了减轻服务器运行负担,所以我打算将一些基本信息初始化,存入缓存中,这样在进行一些初始化的操作的时候就不用老是查询了,极大的减轻了服务器的负担,同时用户体验会大大改善。
废话不多说我开始把核心的代码放出来,一起看下。
与之前的模块功能做法类似 ,唯一麻烦的是数据查询语句稍微难写一点。
查询语句:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.duruiqi.dao.BlogDao">
<resultMap type="Blog" id="BlogResult">
<result property="id" column="id"/>
<result property="title" column="title"/>
<result property="summary" column="summary"/>
<result property="releaseDate" column="releaseDate"/>
<result property="clickHit" column="clickHit"/>
<result property="replyHit" column="replyHit"/>
<result property="content" column="content"/>
<result property="keyWord" column="keyWord"/>
</resultMap>
<select id="countList" resultMap="BlogResult">
SELECT DATE_FORMAT(releaseDate,‘%Y年%m月‘) AS releaseDateStr,COUNT(*) AS blogCount FROM t_blog GROUP BY DATE_FORMAT(releaseDate,‘%Y年%m月‘) ORDER BY DATE_FORMAT(releaseDate,‘%Y年%m月‘) DESC;
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.duruiqi.dao.BlogTypeDao">
<resultMap type="BlogType" id="BlogTypeResult">
<result property="id" column="id"/>
<result property="typeName" column="typeName"/>
<result property="orderNo" column="orderNo"/>
</resultMap>
<select id="countList" resultMap="BlogTypeResult">
SELECT t2.id,t2.typeName,COUNT(t1.id) AS blogCount FROM t_blog t1 RIGHT JOIN t_blogType t2 ON t1.typeId=t2.id GROUP BY t2.typeName ORDER BY t2.orderNo;
</select>
</mapper>
监听控件
BlogTypeService blogTypeService=(BlogTypeService) applicationContext.getBean("blogTypeService");
List<BlogType> blogTypeCountList=blogTypeService.countList(); // 查询博客类别以及博客的数量
application.setAttribute("blogTypeCountList", blogTypeCountList);
BlogService blogService=(BlogService) applicationContext.getBean("blogService");
List<Blog> blogCountList=blogService.countList(); // 根据日期分组查询博客
application.setAttribute("blogCountList", blogCountList);
页面获取
<c:forEach var="blogTypeCount" items="${blogTypeCountList }">
<li><span><a href="#">${blogTypeCount.typeName }(${blogTypeCount.blogCount })</a></span></li>
</c:forEach>
<c:forEach var="blogCount" items="${blogCountList }">
<li><span><a href="#">${blogCount.releaseDateStr }(${blogCount.blogCount })</a></span></li>
</c:forEach>
页面效果:
基础信息初始化到此就结束了,很简单的,O(∩_∩)O哈哈~
【正在看本人博客的这位童鞋,我看你气度不凡,谈吐间隐隐有王者之气,日后必有一番作为!下面有个“顶”字,你就顺手把它点了吧(要先登录CSDN账号哦 )】
—–乐于分享,共同进步!
—–更多文章请看:http://blog.csdn.net/duruiqi_fx
时间: 2024-10-07 02:48:32