文章目录
图书商城系统
一、项目演示
网上书城
二、项目介绍
语言:java 数据库:MySQL
技术栈:javaweb、Servlet、JSP、JDBC、、Tomcat
系统角色:管理员、用户
管理员:书籍管理、分类管理、订单管理、用户管理、上架书籍等功能
用户:登录、注册、图书列表、商品详情、加入购物车、订单列表、订单详情等功能
三、万字项目文档
四、部分功能截图
五、部分代码展示
java
package com.shine.bookshop.dao.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.shine.bookshop.bean.Admin;
import com.shine.bookshop.bean.PageBean;
import com.shine.bookshop.dao.AdminDao;
import com.shine.bookshop.util.DateUtil;
import com.shine.bookshop.util.DbUtil;
public class AdminDaoImpl implements AdminDao {
/**
* @param user 传递要登录的用户信息
* @return 返回一个boolean值,true登录成功,false失败
*/
@Override
public boolean userLogin(Admin admin) {
boolean flag=false;
String sql="select * from s_admin where userName=? and passWord=?";
String sql2="update s_admin set lastLoginTime=? where id=?";
List<Map<String,Object>> list=DbUtil.executeQuery(sql, admin.getUserName(),admin.getPassWord());
if(list.size()>0){
flag=true;
//这里需要name值传入对象中
admin.setName((String)list.get(0).get("name"));
//通过登录成功用户的id更新最后登录时间
DbUtil.excuteUpdate(sql2, DateUtil.getTimestamp(),list.get(0).get("id"));
}
return flag;
}
/**
* @param pageBean 传递分页对象
* @return 返回一个list集合,这里是通过limit分页查询的结果
*/
@Override
public List<Admin> userList(PageBean pageBean) {
List<Admin> lu=new ArrayList<>();
List<Map<String, Object>> list=new ArrayList<Map<String,Object>>();
String sql="select * from s_admin limit ?,?";
list=DbUtil.executeQuery(sql,(pageBean.getCurPage()-1)*pageBean.getMaxSize(),pageBean.getMaxSize());
if(list.size()>0) {
for(Map<String,Object> map:list) {
Admin u=new Admin(map);
lu.add(u);
}
}
return lu;
}
/**
* @param user 要增加的用户对象
* @return 返回一个boolean true用户增加成功 false用户增加失败
*/
@Override
public boolean userAdd(Admin user) {
String sql="insert into s_admin(userName,password,name) values(?,?,?)";
int i= DbUtil.excuteUpdate(sql, user.getUserName(),user.getPassWord(),user.getName());
return i>0?true:false;
}
/**
* @param id 根据id查找一个用户信息
* @return 返回一个list用户信息集合
*/
//查找指定id用户信息
@Override
public Admin findUser(Integer id) {
String sql="select * from s_admin where id=?";
Admin admin=null;
List<Map<String,Object>> list=DbUtil.executeQuery(sql, id);
if(list.size()>0) {
admin=new Admin(list.get(0));
}
return admin;
}
//查找用户名是否存在true存在
@Override
public boolean findUser(String userName) {
String sql="select * from s_admin where userName=?";
List<Map<String,Object>> list=DbUtil.executeQuery(sql, userName);
return list.size()>0?true:false;
}
/**
*
* @param admin 更新用户,根据传过来的id
* @return boolean
*/
@Override
public boolean userUpdate(Admin admin) {
String sql="update s_admin set password=? , name=? where id =?";
int i=DbUtil.excuteUpdate(sql, admin.getPassWord(),admin.getName(),admin.getId());
return i>0?true:false;
}
/**
* @param id 要删除的用户id
* @return 返回boolean true删除用户成功,false删除用户失败
*/
@Override
public boolean delUser(int id) {
String sql="delete from s_admin where id=?";
int i=DbUtil.excuteUpdate(sql, id);
return i>0?true:false;
}
/**
* @param ids 要批量删除id组的字符串
*/
@Override
public boolean batDelUser(String ids) {
String sql="delete from s_admin where id in ("+ids+")";
int i=DbUtil.excuteUpdate(sql);
return i>0?true:false;
}
@Override
public long bookReadCount() {
long count=0;
String sql="select count(*) as count from s_admin";
List<Map<String, Object>> lm=DbUtil.executeQuery(sql);
if(lm.size()>0){
count=(long) lm.get(0).get("count");
}
return count;
}
}
java
package com.shine.bookshop.dao.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.shine.bookshop.bean.Book;
import com.shine.bookshop.bean.Catalog;
import com.shine.bookshop.bean.PageBean;
import com.shine.bookshop.bean.UpLoadImg;
import com.shine.bookshop.dao.BookDao;
import com.shine.bookshop.util.DateUtil;
import com.shine.bookshop.util.DbUtil;
public class BookDaoImpl implements BookDao {
@Override
public List<Book> bookList(PageBean pageBean) {
List<Book> list = new ArrayList<>();
String sql = "select * from view_book limit ?,?";
// 查询的分页结果集
List<Map<String, Object>> lm = DbUtil.executeQuery(sql, (pageBean.getCurPage() - 1) * pageBean.getMaxSize(),
pageBean.getMaxSize());
// 把查询的book结果由List<Map<String, Object>>转换为List<Book>
if (lm.size() > 0) {
for (Map<String, Object> map : lm) {
Book book = new Book(map);
list.add(book);
}
}
return list;
}
@Override
public long bookReadCount() {
String sql = "select count(*) as count from s_book";
List<Map<String, Object>> lm = DbUtil.executeQuery(sql);
return lm.size() > 0 ? (long) lm.get(0).get("count") : 0;
}
@Override
public boolean bookAdd(Book book) {
String sql = "insert into s_book(bookName,catalogId,author,press,price,description,imgId,addTime) values(?,?,?,?,?,?,?,?)";
int i = DbUtil.excuteUpdate(sql, book.getBookName(), book.getCatalog().getCatalogId(), book.getAuthor(),
book.getPress(), book.getPrice(), book.getDescription(), book.getUpLoadImg().getImgId(),
DateUtil.getTimestamp());
return i > 0 ? true : false;
}
@Override
public Book findBookById(int bookId) {
String sql = "select * from view_book where bookId=?";
Book book = null;
List<Map<String, Object>> list = DbUtil.executeQuery(sql, bookId);
if (list.size() > 0) {
book = new Book(list.get(0));
}
return book;
}
/**
*
*/
@Override
public boolean findBookByBookName(String bookName) {
String sql = "select * from s_book where bookName=?";
List<Map<String, Object>> list = DbUtil.executeQuery(sql, bookName);
return list.size() > 0 ? true : false;
}
/**
* 更新图书信息
*/
@Override
public boolean bookUpdate(Book book) {
String sql = "update s_book set catalogId=?,author=?,press=?,price=?,description=? where bookId=?";
int i = DbUtil.excuteUpdate(sql, book.getCatalogId(), book.getAuthor(), book.getPress(), book.getPrice(),
book.getDescription(), book.getBookId());
return i > 0 ? true : false;
}
/**
* 图书删除
*/
@Override
public boolean bookDelById(int bookId) {
String sql = "SET FOREIGN_KEY_CHECKS = 0;delete from s_book where bookId=?";
int i = DbUtil.excuteUpdate(sql, bookId);
return i > 0 ? true : false;
}
/**
* 批量查询
*/
@Override
public String findimgIdByIds(String ids) {
String imgIds = "";
String sql = "select imgId from s_book where bookId in(" + ids + ")";
List<Map<String, Object>> list = DbUtil.executeQuery(sql);
if (list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
if (i != list.size() - 1) {
imgIds += list.get(i).get("imgId") + ",";
} else {
imgIds += list.get(i).get("imgId");
}
}
}
return imgIds;
}
// 批量删除
@Override
public boolean bookBatDelById(String ids) {
String sql = "delete from s_book where bookId in(" + ids + ")";
int i = DbUtil.excuteUpdate(sql);
return i > 0 ? true : false;
}
// 随机查询一定数量的书
@Override
public List<Book> bookList(int num) {
List<Book> list = new ArrayList<>();
String sql = "select * from view_book order by rand() LIMIT ?";
List<Map<String, Object>> lm = DbUtil.executeQuery(sql, num);
// 把查询的book结果由List<Map<String, Object>>转换为List<Book>
if (lm.size() > 0) {
for (Map<String, Object> map : lm) {
Book book = new Book(map);
list.add(book);
}
}
return list;
}
/**
* 查询指定数量新书
*/
@Override
public List<Book> newBooks(int num) {
List<Book> list = new ArrayList<>();
String sql = "SELECT * FROM view_book ORDER BY addTime desc limit 0,?";
List<Map<String, Object>> lm = DbUtil.executeQuery(sql, num);
// 把查询的book结果由List<Map<String, Object>>转换为List<Book>
if (lm.size() > 0) {
for (Map<String, Object> map : lm) {
Book book = new Book(map);
list.add(book);
}
}
return list;
}
/**
* 按分类id统计图书数量
*/
@Override
public long bookReadCount(int catalogId) {
String sql = "select count(*) as count from s_book where catalogId=?";
List<Map<String, Object>> lm = DbUtil.executeQuery(sql, catalogId);
return lm.size() > 0 ? (long) lm.get(0).get("count") : 0;
}
/**
* 按分类id获取图书列表
*/
@Override
public List<Book> bookList(PageBean pageBean, int catalogId) {
List<Book> list = new ArrayList<>();
String sql = "select * from view_book where catalogId=? limit ?,?";
// 查询的分页结果集
List<Map<String, Object>> lm = DbUtil.executeQuery(sql, catalogId,
(pageBean.getCurPage() - 1) * pageBean.getMaxSize(), pageBean.getMaxSize());
// 把查询的book结果由List<Map<String, Object>>转换为List<Book>
if (lm.size() > 0) {
for (Map<String, Object> map : lm) {
Book book = new Book(map);
list.add(book);
}
}
return list;
}
/**
* 按分类id获取图书列表
*/
@Override
public List<Book> bookList(PageBean pageBean, String bookname) {
List<Book> list = new ArrayList<>();
String sql = "select * from view_book where bookName like '%"+bookname+"%' limit ?,?";
// 查询的分页结果集
List<Map<String, Object>> lm = DbUtil.executeQuery(sql,
(pageBean.getCurPage() - 1) * pageBean.getMaxSize(), pageBean.getMaxSize());
// 把查询的book结果由List<Map<String, Object>>转换为List<Book>
if (lm.size() > 0) {
for (Map<String, Object> map : lm) {
Book book = new Book(map);
list.add(book);
}
}
return list;
}
@Override
public long bookReadCount(String bookname) {
String sql = "select count(*) as count from s_book where bookName like '%"+bookname+"%'";
List<Map<String, Object>> lm = DbUtil.executeQuery(sql);
return lm.size() > 0 ? (long) lm.get(0).get("count") : 0;
}
}
java
package com.shine.bookshop.dao.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.shine.bookshop.bean.Catalog;
import com.shine.bookshop.bean.PageBean;
import com.shine.bookshop.dao.CatalogDao;
import com.shine.bookshop.util.DbUtil;
public class CatalogDaoImpl implements CatalogDao {
/**
* 获取图书分类信息
*/
@Override
public List<Catalog> catalogList(PageBean pb) {
List<Catalog> list=new ArrayList<Catalog>();
String sql = "select * from s_catalog limit ?,?";
// 查询的分页结果集
List<Map<String, Object>> lm = DbUtil.executeQuery(sql, (pb.getCurPage() - 1) * pb.getMaxSize(),
pb.getMaxSize());
if(lm.size()>0){
for(Map<String,Object> map:lm){
Catalog catalog=new Catalog(map);
list.add(catalog);
}
}
return list;
}
@Override
public long catalogReadCount() {
long count=0;
String sql="select count(*) as count from s_catalog";
List<Map<String, Object>> lm=DbUtil.executeQuery(sql);
if(lm.size()>0){
count=(long) lm.get(0).get("count");
}
return count;
}
@Override
public List<Catalog> getCatalog() {
List<Catalog> list=new ArrayList<Catalog>();
String sql="select * from s_catalog";
List<Map<String,Object>> lmso=DbUtil.executeQuery(sql);
if(lmso.size()>0){
for(Map<String,Object> map:lmso){
Catalog catalog=new Catalog(map);
list.add(catalog);
}
}
return list;
}
@Override
public boolean catalogDel(int catalogId) {
String sql = "delete from s_catalog where catalogId=?";
int i = DbUtil.excuteUpdate(sql, catalogId);
return i > 0 ? true : false;
}
@Override
public boolean catalogBatDelById(String ids) {
String sql="delete from s_catalog where catalogId in("+ids+")";
int i=DbUtil.excuteUpdate(sql);
return i>0?true:false;
}
@Override
public boolean findCatalogByCatalogName(String catalogName) {
String sql = "select * from s_catalog where catalogName=?";
List<Map<String, Object>> list = DbUtil.executeQuery(sql, catalogName);
return list.size() > 0 ? true : false;
}
@Override
public boolean catalogAdd(String catalogName) {
String sql="insert into s_catalog(catalogName) values(?)";
int i = DbUtil.excuteUpdate(sql, catalogName);
return i > 0 ? true : false;
}
}
六、底部获取项目源码带万字文档(9.9¥带走)
有问题,或者需要协助调试运行项目的也可以