标签:blog io 使用 for sp 数据 on 2014 log
网站页面的导航栏是从数据库中生成出来的,所以在界面上展示导航栏时,要从数据库中读取出来,但不能每次显示一个页面都从数据库中读,这样就很浪费性能,应该考虑把导航栏放到一个缓存中。如:session、application、memcache等。
对于访问量小的网站,也可以使用如下方法:
@Component public class NavigationUtil { public static List<BeautifulClassEntity> beautifulClassList; public static List<ActivityClassEntity> activityClassList; public static List<BeautifulClassEntity> getBeautifulClassList(){ if(beautifulClassList == null){ beautifulClassList = beautifulClassService.getAllBeautifulClass(); } return beautifulClassList; } public static List<ActivityClassEntity> getActivityClassList(){ if(activityClassList == null){ activityClassList = activityService.getActivityList(); } return activityClassList; } private static BeautifulClassService beautifulClassService; private static ActivityService activityService; @Autowired public void setBeautifulClassService(BeautifulClassService beautifulClassService) { NavigationUtil.beautifulClassService = beautifulClassService; } @Autowired public void setActivityService(ActivityService activityService) { NavigationUtil.activityService = activityService; } public String getTest(){ return "aa"; } }
<% List<BeautifulClassEntity> beautifulList = NavigationUtil.getBeautifulClassList(); for(BeautifulClassEntity beautiful : beautifulList){ %> <a href="/beautiful/cloth.do?beautifulClassId=<%=beautiful.getId() %>" class="main_title_nav_cur"> <%=beautiful.getBeautifulName() %> </a> <% } %>
以上皆为本人总结所得,如果不妥之处,敬请提出,共同学习。。。
标签:blog io 使用 for sp 数据 on 2014 log
原文地址:http://blog.csdn.net/yanlianglu/article/details/40427251