博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
cms-幻灯片的实现
阅读量:5278 次
发布时间:2019-06-14

本文共 15017 字,大约阅读时间需要 50 分钟。

1.其实幻灯片的后台代码和之前的最新动态和推荐是一样的,只是前台遍历的时候不一样罢了

2.代码:

 2.1:帖子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.open1111.dao.ArticleDao">

<resultMap type="Article" id="ArticleResult">

<result property="id" column="id"/>
<result property="title" column="title"/>
<result property="publishDate" column="publishDate"/>
<result property="content" column="content"/>
<result property="summary" column="summary"/>
<result property="titleColor" column="titleColor"/>
<result property="click" column="click"/>
<result property="isRecommend" column="isRecommend"/>
<result property="isSlide" column="isSlide"/>
<result property="keyWords" column="keyWords"/>
<association property="arcType" column="typeId" select="com.open1111.dao.ArcTypeDao.findById"></association>
</resultMap>
<select id="getNewest" resultMap="ArticleResult">
select * from t_article order by publishDate desc limit 0,7
</select>
<select id="getRecommend" resultMap="ArticleResult">
select * from t_article where isRecommend=1 order by publishDate desc limit 0,7
</select>
<select id="getSlide" resultMap="ArticleResult">
select * from t_article where isSlide=1 order by publishDate desc limit 0,5
</select>
</mapper>

2.2:修改mapper同时修改到接口:

package com.open1111.dao;

import java.util.List;

import com.open1111.entity.Article;

/**

* 帖子Dao接口
* @author user
*
*/
public interface ArticleDao {

/**

* 获取最新的7条帖子
* @return
*/
public List<Article> getNewest();
/**
* 获取最新7条推荐的帖子
* @return
*/
public List<Article> getRecommend();
/**
* 获取最新5条幻灯的帖子
* @return
*/
public List<Article> getSlide();
}

2.3.帖子service添加查询幻灯片的方法:

  

package com.open1111.service;

import java.util.List;

import com.open1111.entity.Article;

/**

* 帖子Service接口
* @author user
*
*/
public interface ArticleService {

/**

* 获取最新的7条帖子
* @return
*/
public List<Article> getNewest();
/**
* 获取最新7条推荐的帖子
* @return
*/
public List<Article> getRecommend();
/**
* 获取最新5条幻灯的帖子
* @return
*/
public List<Article> getSlide();
}

2.4帖子serviceImpl中添加查询幻灯片的方法:

package com.open1111.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.open1111.dao.ArticleDao;

import com.open1111.entity.Article;
import com.open1111.service.ArticleService;

/**

* 帖子Service实现类
* @author user
*
*/
@Service("articleService")
public class ArticleServiceImpl implements ArticleService{

@Resource

private ArticleDao articleDao;
public List<Article> getNewest() {
return articleDao.getNewest();
}

public List<Article> getRecommend() {

return articleDao.getRecommend();
}

public List<Article> getSlide() {

return articleDao.getSlide();
}

}

2.5:在静态化组件serviceImpl中把幻灯片数据存入application中

package com.open1111.service.impl;

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 user
*
*/
@Component("initComponet")
public class InitComponet implements ApplicationContextAware,ServletContextListener{

private static ApplicationContext applicationContext;

public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
// TODO Auto-generated method stub
this.applicationContext=applicationContext;
System.out.println(this);
}
/**
* 刷新application缓存方法
* @param application
*/
public void refreshSystem(ServletContext application){
LinkService linkService=(LinkService) applicationContext.getBean("linkService");
List<Link> linkList=linkService.list(null);
application.setAttribute("linkList", linkList);
ArcTypeService arcTypeService=(ArcTypeService) applicationContext.getBean("arcTypeService");
List<ArcType> arcTypeList=arcTypeService.list(null);
application.setAttribute("arcTypeList", arcTypeList);
ArticleService articleService=(ArticleService) applicationContext.getBean("articleService");
List<Article> newestArticleList=articleService.getNewest(); // 获取最新7条帖子
application.setAttribute("newestArticleList", newestArticleList);
List<Article> recommendArticleList=articleService.getRecommend();
application.setAttribute("recommendArticleList", recommendArticleList);
List<Article> slideArticleList=articleService.getSlide();
application.setAttribute("slideArticleList", slideArticleList);
}

public void contextInitialized(ServletContextEvent sce) {

// TODO Auto-generated method stub
ServletContext application=sce.getServletContext();
refreshSystem(application);
}

public void contextDestroyed(ServletContextEvent sce) {

// TODO Auto-generated method stub
}

}

2.6:在页面显示幻灯片效果:

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Open1111官方网站 -南通小锋网络科技有限公司</title>
<META NAME="Author" CONTENT="Java1234_小锋老师">
<meta name="keywords"
content="Java内容管理系统,JavaCMS,Java开源,Java爬虫,JavaSEO,Java CMS" />
<meta name="description"
content="Open1111专注于研发Java建站,Java爬虫,JavaSEO教程.传授广大学员用Java技术来实现互联网资源的搬运,整合汇聚互联网资源建站,顺便获取一些搬运费补贴家用." />
<link rel="stylesheet"
href="${pageContext.request.contextPath}/static/css/open1111.css">
<script src="${pageContext.request.contextPath}/static/js/jQuery.js"></script>
</head>
<body>
<jsp:include page="/common/head.jsp"></jsp:include>
<jsp:include page="/common/menu.jsp"></jsp:include>

<div class="content">

<div class="w960">

<div class="left">

<DIV style="width: 330px; height: 228px;" class="tuhuo">
<A href="" target="_blank"><IMG style="width: 330px; height: 208px;" id="fou_img" src=""></A>
<c:forEach var="article" items="${slideArticleList }">
<A href="${pageContext.request.contextPath}/article/${article.id}.html">
<IMG style="display: none;" class="tu_img"
src="${pageContext.request.contextPath}/static/userImages/${article.slideImage}"
width="330" height="208" />
</A>
</c:forEach>
<c:forEach var="article" items="${slideArticleList }">
<P style="height: 20px;" class="tc">
<A href="${pageContext.request.contextPath}/article/${article.id}.html" target="_blank" title="${article.title }">${fn:substring(article.title,0,18) }</A>
</P>
</c:forEach>
<UL>
<LI class="fouce">1</LI>
<LI>2</LI>
<LI>3</LI>
<LI>4</LI>
<LI>5</LI>
</UL>
</DIV>

</div>

<div class="middle">

<div class="data_list">

<div class="dataHeader">最近更新</div>
<div class="datas">
<ul>
<c:forEach var="article" items="${newestArticleList }">
<li><a target="_blank" href="${pageContext.request.contextPath}/article/${article.id}.html"
title="${article.title }">[<fmt:formatDate value="${article.publishDate }" pattern="MM-dd"/>]&nbsp;&nbsp;<font
color="${article.titleColor }">${fn:substring(article.title,0,20) }</font></a></li>
</c:forEach>
</ul>
</div>
</div>

</div>

<div class="right">

<div class="data_list">
<div class="dataHeader">站长推荐</div>
<div class="datas">
<ul>
<c:forEach var="article" items="${recommendArticleList }">
<li><a target="_blank" href="${pageContext.request.contextPath}/article/${article.id}.html"
title="${article.title }"><font color="${article.titleColor }">${fn:substring(article.title,0,16) }</font></a></li>
</c:forEach>

</ul>

</div>
</div>

</div>

 

<div class="w960 article_row">

<div class="data_list article_list">

 

<div class="dataHeader">

Java基础<span class="more"><a href="/arcType/1.html">更多...</a></span>
</div>
<div class="datas">
<ul>

<li>[11-05]&nbsp;&nbsp;<a href="/article/72.html"

title="Java基本数据类型-数据类型分类"><font color="">Java基本数据类型-数据类型分类</font></a></li>

 

<li>[11-05]&nbsp;&nbsp;<a href="/article/71.html"

title="Java中的关键字"><font color="">Java中的关键字</font></a></li>

 

<li>[11-05]&nbsp;&nbsp;<a href="/article/70.html"

title="Java标识符命名"><font color="">Java标识符命名</font></a></li>

 

<li>[11-05]&nbsp;&nbsp;<a href="/article/69.html"

title="java注释"><font color="">java注释</font></a></li>

 

<li>[11-05]&nbsp;&nbsp;<a href="/article/68.html"

title="Java HelloWorld实现及Java运行原理介绍"><font color="#FF0000">Java
HelloWorld实现及</font></a></li>

 

<li>[11-05]&nbsp;&nbsp;<a href="/article/67.html"

title="Java运行环境搭建之Jdk配置"><font color="#FF0000">Java运行环境搭建之Jdk配置</font></a></li>

 

<li>[11-05]&nbsp;&nbsp;<a href="/article/66.html"

title="Java简介"><font color="">Java简介</font></a></li>

 

<li>[11-05]&nbsp;&nbsp;<a href="/article/65.html"

title="Java HelloWorld实现"><font color="">Java
HelloWorld实现</font></a></li>

</ul>

</div>

 

</div>

<div class="data_list article_list" style="margin-left: 12px">

<div class="dataHeader">
网页基础<span class="more"><a href="/arcType/2.html">更多...</a></span>
</div>
<div class="datas">
<ul>

<li>[11-28]&nbsp;&nbsp;<a href="/article/143.html"

title="css 属性选择器"><font color="">css 属性选择器</font></a></li>

 

<li>[11-28]&nbsp;&nbsp;<a href="/article/142.html"

title="css 类选择器"><font color="">css 类选择器</font></a></li>

 

<li>[11-28]&nbsp;&nbsp;<a href="/article/141.html"

title="css id 选择器"><font color="">css id 选择器</font></a></li>

 

<li>[11-08]&nbsp;&nbsp;<a href="/article/82.html"

title="HTML文本排版"><font color="">HTML文本排版</font></a></li>

 

<li>[11-08]&nbsp;&nbsp;<a href="/article/81.html"

title="HTML入门程序"><font color="">HTML入门程序</font></a></li>

 

<li>[11-08]&nbsp;&nbsp;<a href="/article/80.html"

title="Web基础"><font color="">Web基础</font></a></li>

 

<li>[11-06]&nbsp;&nbsp;<a href="/article/76.html"

title="基本的 HTML 标签"><font color="">基本的 HTML 标签</font></a></li>

 

<li>[11-06]&nbsp;&nbsp;<a href="/article/75.html"

title="HTML 简介"><font color="">HTML 简介</font></a></li>

</ul>

</div>
</div>

 

 

 

 

<div class="data_list article_list" style="margin-left: 12px">

<div class="dataHeader">
Java建站<span class="more"><a href="/arcType/4.html">更多...</a></span>
</div>
<div class="datas">
<ul>

<li>[01-24]&nbsp;&nbsp;<a href="/article/86.html"

title="做活动,领取百度云搜索引擎V2.0源码"><font color="#FF0000">做活动,领取百度云搜索引擎V2.0源</font></a></li>

 

<li>[01-03]&nbsp;&nbsp;<a href="/article/151.html"

title="Tomcat OutOfMemoryError PermGen space 的解决办法"><font
color="">Tomcat OutOfMemory</font></a></li>

 

<li>[12-04]&nbsp;&nbsp;<a href="/article/147.html"

title="http content-type常见文件格式类型"><font color="">http
content-type常</font></a></li>

 

<li>[12-04]&nbsp;&nbsp;<a href="/article/145.html"

title="主机"><font color="">主机</font></a></li>

 

<li>[12-03]&nbsp;&nbsp;<a href="/article/144.html"

title="域名"><font color="">域名</font></a></li>

 

<li>[11-09]&nbsp;&nbsp;<a href="/article/85.html"

title="解决Url带中文参数乱码问题"><font color="">解决Url带中文参数乱码问题</font></a></li>

 

<li>[11-09]&nbsp;&nbsp;<a href="/article/84.html"

title="Tomcat多域名配置"><font color="">Tomcat多域名配置</font></a></li>

 

<li>[11-06]&nbsp;&nbsp;<a href="/article/77.html"

title="如何发布Web项目到互联网"><font color="#FF0000">如何发布Web项目到互联网</font></a></li>

</ul>

</div>
</div>

 

</div>

<div class="w960 article_row">

 

 

<div class="data_list article_list">

 

<div class="dataHeader">

Java爬虫<span class="more"><a href="/arcType/5.html">更多...</a></span>
</div>
<div class="datas">
<ul>

<li>[01-24]&nbsp;&nbsp;<a href="/article/152.html"

title="做活动,领取Java爬虫-Java包下载网源码"><font color="#FF0000">做活动,领取Java爬虫-Java包</font></a></li>

 

<li>[12-04]&nbsp;&nbsp;<a href="/article/146.html"

title="透明代理、匿名代理、混淆代理、高匿代理有什么区别?"><font color="">透明代理、匿名代理、混淆代理、高匿代</font></a></li>

 

<li>[11-21]&nbsp;&nbsp;<a href="/article/140.html"

title="HttpClient HTTP缓存"><font color="">HttpClient
HTTP缓存</font></a></li>

 

<li>[11-21]&nbsp;&nbsp;<a href="/article/139.html"

title="HttpClient 响应处理"><font color="">HttpClient
响应处理</font></a></li>

 

<li>[11-21]&nbsp;&nbsp;<a href="/article/138.html"

title="Easy to use facade API"><font color="">Easy
to use facade</font></a></li>

 

<li>[11-20]&nbsp;&nbsp;<a href="/article/137.html"

title="HttpClient SPNEGO/Kerberos认证"><font color="">HttpClient
SPNEGO/</font></a></li>

 

<li>[11-20]&nbsp;&nbsp;<a href="/article/136.html"

title="HttpClient NTLM连接持久性"><font color="">HttpClient
NTLM连接持</font></a></li>

 

<li>[11-20]&nbsp;&nbsp;<a href="/article/135.html"

title="HttpClient NTLM认证"><font color="">HttpClient
NTLM认证</font></a></li>

</ul>

</div>
</div>

 

 

 

 

<div class="data_list article_list" style="margin-left: 12px">

<div class="dataHeader">
网站SEO<span class="more"><a href="/arcType/6.html">更多...</a></span>
</div>
<div class="datas">
<ul>

<li>[11-08]&nbsp;&nbsp;<a href="/article/83.html"

title="搜索引擎工作原理大体过程"><font color="">搜索引擎工作原理大体过程</font></a></li>

 

<li>[11-07]&nbsp;&nbsp;<a href="/article/79.html"

title="为什么要做SEO"><font color="">为什么要做SEO</font></a></li>

 

<li>[11-07]&nbsp;&nbsp;<a href="/article/78.html"

title="什么是SEO"><font color="">什么是SEO</font></a></li>

</ul>

</div>
</div>

 

 

 

 

<div class="data_list article_list" style="margin-left: 12px">

<div class="dataHeader">
广告联盟<span class="more"><a href="/arcType/7.html">更多...</a></span>
</div>
<div class="datas">
<ul>

<li>[12-18]&nbsp;&nbsp;<a href="/article/150.html"

title="广告联盟推荐-搜狗联盟"><font color="">广告联盟推荐-搜狗联盟</font></a></li>

 

<li>[12-18]&nbsp;&nbsp;<a href="/article/149.html"

title="广告联盟推荐-谷歌联盟"><font color="#FF0000">广告联盟推荐-谷歌联盟</font></a></li>

 

<li>[12-18]&nbsp;&nbsp;<a href="/article/148.html"

title="广告联盟推荐-百度联盟"><font color="#FF0000">广告联盟推荐-百度联盟</font></a></li>

 

<li>[11-19]&nbsp;&nbsp;<a href="/article/121.html"

title="广告联盟推荐-大圣联盟(安徽)"><font color="">广告联盟推荐-大圣联盟(安徽)</font></a></li>

 

<li>[11-19]&nbsp;&nbsp;<a href="/article/120.html"

title="广告联盟推荐-百游联盟"><font color="">广告联盟推荐-百游联盟</font></a></li>

 

<li>[11-05]&nbsp;&nbsp;<a href="/article/74.html"

title="广告联盟推荐-七七联盟"><font color="#FF0000">广告联盟推荐-七七联盟</font></a></li>

</ul>

</div>
</div>

 

</div>

 

</div>

</div>

<jsp:include page="/common/link.jsp"></jsp:include>

<jsp:include page="/common/foot.jsp"></jsp:include>
</body>
<script type="text/javascript">
var auto;
var index = 0;
$('.tuhuo ul li').hover(function() {
clearTimeout(auto);
index = $(this).index();
move(index);
}, function() {
auto = setTimeout('autogo(' + index + ')', 3000);
});

function autogo() {

if (index < 3) {
move(index);
index++;
} else {
index = 0;
move(index);
index++;
}
}
function move(l) {
var src = $('.tu_img').eq(index).attr('src');
$("#fou_img").css({
"opacity" : "0"
});
$('#fou_img').attr('src', src);
$('#fou_img').stop(true).animate({
opacity : '1'
}, 1000);
$('.tuhuo ul li').removeClass('fouce');
$('.tuhuo ul li').eq(index).addClass('fouce');
$('.tuhuo p').hide();
$('.tuhuo p').eq(index).show();
var ao = $('.tuhuo p').eq(index).children('a').attr('href');
$('#fou_img').parent('a').attr("href", ao);
}
autogo();
setInterval('autogo()', 3000);
</script>

</html>

 

转载于:https://www.cnblogs.com/csy666/p/6523478.html

你可能感兴趣的文章
c# 文件笔记
查看>>
类和结构
查看>>
心得25--JDK新特性9-泛型1-加深介绍
查看>>
安装NVIDIA驱动时禁用自带nouveau驱动
查看>>
HDU-1255 覆盖的面积 (扫描线)
查看>>
项目管理之路(1):初步踏入项目管理
查看>>
Java 中 静态方法与非静态方法的区别
查看>>
Jenkins+ProGet+Windows Batch搭建全自动的内部包(NuGet)打包和推送及管理平台
查看>>
线程池的概念
查看>>
Java 序列化
查看>>
Java 时间处理实例
查看>>
Java 多线程编程
查看>>
Java 数组实例
查看>>
mysql启动过程
查看>>
2017前端面试题总结
查看>>
Http GetPost网络请求
查看>>
SWIFT国际资金清算系统
查看>>
Sping注解:注解和含义
查看>>
站立会议第四天
查看>>
如何快速掌握一门技术
查看>>