本文主要是介绍网上书城的门户首页功能,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
门户首页功能
- 前言
- 门户首页功能所需的的dao,web及辅助类
- dao
- web
- 辅助类
- 首页界面
- 代码
- css样式
- js代码对应的界面
前言
门户首页功能是客户可以在这页面进行查看书籍
门户首页功能所需的的dao,web及辅助类
dao
bookDao 中新增两个门户新书上架,门户热销书籍的方法
// 门户新书上架的书籍public List<Book> news(Book book,PageBean pageBean) throws Exception{String sql = "select * from t_easyui_book where state =2 order by deploytime desc limit 10";return super.executeQuery(sql, pageBean, Book.class);}// 门户热销书籍public List<Book> hots(Book book,PageBean pageBean) throws Exception{String sql = "select * from t_easyui_book where state =2 order by sales desc limit 12";return super.executeQuery(sql, pageBean, Book.class);}
web
bookAction 中新增newss,hotss两个方法
public String newss(HttpServletRequest request, HttpServletResponse response) {try {List<Book> newsBook = this.bookDao.news(null, null);ResponseUtil.writeJson(response,Result.ok(newsBook));} catch (Exception e) {e.printStackTrace();}return null;}public String hotss(HttpServletRequest request, HttpServletResponse response) {try {List<Book> hots = this.bookDao.hots(null, null);ResponseUtil.writeJson(response,Result.ok(hots));} catch (Exception e) {e.printStackTrace();}return null;}
辅助类
Result 响应结果集
package com.tang.util;
/*** (响应结果集)* @author Administrator** @param <T>*/
public class Result<T> {private int code;private String msg;private T data;public static Result SUCCESS = new Result<>(200,"操作成功");public static <T> Result ok(T data) {return new Result(data);}public int getCode() {return code;}public void setCode(int code) {this.code = code;}public String getMsg() {return msg;}public void setMsg(String msg) {this.msg = msg;}public T getData() {return data;}public void setData(T data) {this.data = data;}private Result(int code, String msg) {super();this.code = code;this.msg = msg;}private Result() {super();}private Result(T data) {super();this.data = data;}}
首页界面
代码
index,jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!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">
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.css" rel="stylesheet"><link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/static/css/fg.css" />
<title>登录后的主界面</title>
</head>
<input type="hidden" id="ctx" value="${pageContext.request.contextPath }">
<body><div class="container"><!-- 横幅 --><div class="row"><div class="col-sm-4">您好,欢迎来到飞凡网上书城 !</div><div class="col-sm-4 offset-sm-4"><a href="#">登陆</a> | <a href="#">注册</a> | <b>我的购物车</b> | <i>网站首页</i></div></div><!-- 搜索栏 --><div class="row"><div class="col-sm-12 search-parent"><!-- 本来这里应该放一张背景图的 --><div class="search"></div><input type="text" id="book_name" name="name" value="" /><button type="button" class="btn btn-primary">搜索</button></div></div><!-- 主内容区 --><div class="row content"><div class="col-sm-3 l-content"><ul class="list-group c-category"><li class="list-group-item text-white">书籍分类</li></ul></div><div class="col-sm-9 r-content"><!-- 广告 --><div class="guanggao"><img src="${pageContext.request.contextPath }/static/img/banner.png" class="img-thumbnail" alt="..."></div><!-- 新书 --><div class="news container"><div class="tip row"><img src="${pageContext.request.contextPath }/static/img/title_bj.png"><h5 class="text-white">新书上架</h5></div></div><!-- 热销 --><div class="hots container"><div class="tip row"><img src="${pageContext.request.contextPath }/static/img/title_bj.png"><h5 class="text-white">热销图书</h5></div></div></div></div><!-- 底部版权 --><div class="row"><div class="col-sm-12 text-center">Copyright ©2020 卓京教育,版权所有</div></div></div><script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.12.4/jquery.js"></script><script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.js"></script><script src="${pageContext.request.contextPath }/static/js/index.js"></script></body>
</html>
css样式
fg.css
*{margin: 0;padding: 0;
}/* 搜索栏 start */
.search-parent{position: relative;height: 100px;/* text-align: center; */
}
.search{position: absolute;background-color: #D6CCBB;width: 1100px;height: 90px;
}
.search-parent input{position: absolute;top: 30px;left: 400px;z-index: 2;
}
.search-parent button{position: absolute;top: 27px;left: 570px;z-index: 2;
}
/* 搜索栏 end *//* 主内容区 start */
.bg-color1{background-color: #710503 ;
}
.bg-color2{background-color: #F7E4E4 ;
}
.bg-opacity{opacity: 0.3;
}
.c-category li{cursor: pointer;
}.guanggao>img{width: 690px;
}
.l-content{padding-right: 0;
}
.r-content{padding: 0;
}.tip{position: relative;height: 40px;/* width: 680px; *//* background-color: #F7F6F6; */
}
.tip>img{position: absolute;
}
.tip>h5{position: absolute;left: 8px;
}
.book img{width: 80px;height: 110px;
}
.book p{margin-bottom: 0;
}.shop-table button:nth-of-type(2){margin: 0 50px;
}
/* .shop-table-btn{margin: 0 50px;
} */
/* 主内容区 end */
js代码对应的界面
$(function(){// 当浏览器访问http://localhost:8080/T243_easyui/index.jsp,ajax要加载书籍列表的数据$.ajax({url:ctx+'/category.action?methodName=list',success:function(data){data = eval('('+data+')');// <li class="list-group-item">青春</li>for(i in data){$(".list-group").append('<li class="list-group-item">'+data[i].name+'</li>');$(".c-category li").eq(0).addClass('bg-color1');$(".c-category li:gt(0)").addClass('bg-color2');$(".c-category li:gt(0)").hover(function() {$(this).addClass('bg-opacity');}, function() {$(this).removeClass('bg-opacity');});}}});})
$(function(){var ctx = $("#ctx").val(); // 加载新书(递归)$.ajax({ url:ctx+'/book.action?methodName=newss',success:function(data){data = eval('('+data+')');
// 给news container所属的div添加row或者列appendBookDiv($(".news"),data.data,0,"");}});// 热销书籍(递归)$.ajax({url:ctx+'/book.action?methodName=hotss',success:function(data){data = eval('('+data+')');
// 给news container所属的div添加row或者列appendBookDiv($(".hots"),data.data,0,"");}});})/** 1、给哪个div追加html类容(jquery对象)* 2、最佳内容的数据来源* 3、标识当前是第几行内容* 4、最终追加的html*/
function appendBookDiv($node,data,level,htmlstr){
// 第一行:0~5var start = level * 6;// data的数据12条var len = data.length;htmlstr += '<div class="row book">';for(i=start;i<start+6;i++){if(i==len) break;htmlstr += '<div class="col-sm-2" style="width: 90px;">';htmlstr += '<img src="'+data[i].image+'" >';htmlstr += '<p>'+data[i].name+'</p>';htmlstr += '<b>¥'+data[i].price+'</b>';htmlstr += '</div>';}htmlstr += '</div>';level++;if(start+6>=len){$node.append(htmlstr);}else{appendBookDiv($node,data,level,htmlstr);}
}
完整的index.js
$(function(){var ctx = $("#ctx").val(); // 当浏览器访问http://localhost:8080/T243_easyui/index.jsp,ajax要加载书籍列表的数据$.ajax({url:ctx+'/category.action?methodName=list',success:function(data){data = eval('('+data+')');
// <li class="list-group-item">青春</li>for(i in data){$(".list-group").append('<li class="list-group-item">'+data[i].name+'</li>');$(".c-category li").eq(0).addClass('bg-color1');$(".c-category li:gt(0)").addClass('bg-color2');$(".c-category li:gt(0)").hover(function() {$(this).addClass('bg-opacity');}, function() {$(this).removeClass('bg-opacity');});}}});// 加载新书(递归)$.ajax({ url:ctx+'/book.action?methodName=newss',success:function(data){data = eval('('+data+')');
// 给news container所属的div添加row或者列appendBookDiv($(".news"),data.data,0,"");}});// 热销书籍(递归)$.ajax({url:ctx+'/book.action?methodName=hotss',success:function(data){data = eval('('+data+')');
// 给news container所属的div添加row或者列appendBookDiv($(".hots"),data.data,0,"");}});})/** 1、给哪个div追加html类容(jquery对象)* 2、最佳内容的数据来源* 3、标识当前是第几行内容* 4、最终追加的html*/
function appendBookDiv($node,data,level,htmlstr){
// 第一行:0~5var start = level * 6;// data的数据12条var len = data.length;htmlstr += '<div class="row book">';for(i=start;i<start+6;i++){if(i==len) break;htmlstr += '<div class="col-sm-2" style="width: 90px;">';htmlstr += '<img src="'+data[i].image+'" >';htmlstr += '<p>'+data[i].name+'</p>';htmlstr += '<b>¥'+data[i].price+'</b>';htmlstr += '</div>';}htmlstr += '</div>';level++;if(start+6>=len){$node.append(htmlstr);}else{appendBookDiv($node,data,level,htmlstr);}
}
这篇关于网上书城的门户首页功能的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!