Bootstrap

基于javaweb+mysql的ssm文具学习用品商城系统(java+ssm+jsp+jquery+mysql)

基于javaweb+mysql的ssm文具学习用品商城系统(java+ssm+jsp+jquery+mysql)

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb的SSM文具学习用品商城系统(java+ssm+jsp+jquery+mysql)

项目介绍

本项目分为前后台,前台为普通用户登录,后台为管理员登录;

管理员角色包含以下功能: 管理员登录,管理员信息管理,查看用户信息,新闻公告信息管理,文具类型信息管理,城市信息管理,配货点信息管理,文具信息管理,订单信息管理,查看评价信息等功能。

用户角色包含以下功能: 按分类查看,用户登录,查看商品详情,加入购物车,提交订单,查看订单,修改个人信息,查看网站公告,查看配货站等功能。

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目:否;

技术栈

  1. 后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+CSS+JavaScript+jQuery

使用说明

  1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中springmvc-servlet.xml配置文件中的数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入http://localhost:8080/ 登录
			return "redirect:/index/preLogin.action";
		}
		return "users/editpwd";
	}

	// 修改密码
	@RequestMapping("editpwd.action")
	public String editpwd() {
		this.front();
		if (this.getSession().getAttribute("userid") == null) {
			return "redirect:/index/preLogin.action";
		}
		String userid = (String) this.getSession().getAttribute("userid");
		String password = this.getRequest().getParameter("password");
		String repassword = this.getRequest().getParameter("repassword");
		Users users = this.usersService.getUsersById(userid);
		if (password.equals(users.getPassword())) {
			users.setPassword(repassword);
			this.usersService.updateUsers(users);
		} else {
			this.getSession().setAttribute("message", "旧密码错误");
			return "redirect:/index/prePwd.action";
		}
		return "redirect:/index/prePwd.action";
	}

	@RequestMapping("usercenter.action")
	public String usercenter() {
		this.front();
		if (this.getSession().getAttribute("userid") == null) {
			return "redirect:/index/preLogin.action";
		}
		return "users/usercenter";
	}

	@RequestMapping("userinfo.action")
	public String userinfo() {
		this.front();
		if (this.getSession().getAttribute("userid") == null) {
			return "redirect:/index/preLogin.action";
		}
		String userid = (String) this.getSession().getAttribute("userid");

//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/cart", produces = "text/plain;charset=utf-8")
public class CartAction extends BaseAction {
	// 注入Service 由于标签的存在 所以不需要getter setter
	@Autowired
	@Resource
	private CartService cartService;
	@Autowired
	@Resource
	private UsersService usersService;
	@Autowired
	@Resource
	private JiancaiService jiancaiService;

	// 准备添加数据
	@RequestMapping("createCart.action")
	public String createCart() {
		List<Users> usersList = this.usersService.getAllUsers();
		this.getRequest().setAttribute("usersList", usersList);
		List<Jiancai> jiancaiList = this.jiancaiService.getAllJiancai();
		this.getRequest().setAttribute("jiancaiList", jiancaiList);
		return "admin/addcart";
	}

	// 添加数据
	@RequestMapping("addCart.action")
	public String addCart(Cart cart) {
		this.cartService.insertCart(cart);
		return "admin/listadmin";
	}

	// 按条件查询数据 (模糊查询)
	@RequestMapping("queryAdminByCond.action")
	public String queryAdminByCond(String cond, String name, String number) {
		Admin admin = new Admin();
		if (cond != null) {
			if ("username".equals(cond)) {
				admin.setUsername(name);
			}
			if ("password".equals(cond)) {
				admin.setPassword(name);
			}
			if ("realname".equals(cond)) {
				admin.setRealname(name);
			}
			if ("contact".equals(cond)) {
				admin.setContact(name);
			}
			if ("addtime".equals(cond)) {
				admin.setAddtime(name);
			}
		}

		List<String> nameList = new ArrayList<String>();
		List<String> valueList = new ArrayList<String>();
		nameList.add(cond);
		valueList.add(name);
		PageHelper.getPage(this.adminService.getAdminByLike(admin), "admin", nameList, valueList, 10, number, this.getRequest(), "query");
		name = null;
		cond = null;
		return "admin/queryadmin";
	}

	// 按主键查询数据
	@RequestMapping("getAdminById.action")
	public String getAdminById(String id) {
		Admin admin = this.adminService.getAdminById(id);
		this.getRequest().setAttribute("admin", admin);
		if (this.getSession().getAttribute("userid") == null) {
			return "redirect:/index/preLogin.action";
		}
		String userid = (String) this.getSession().getAttribute("userid");
		this.getSession().setAttribute("users", this.usersService.getUsersById(userid));
		return "users/userinfo";
	}

	@RequestMapping("personal.action")
	public String personal(Users users) {
		this.front();
		if (this.getSession().getAttribute("userid") == null) {
			return "redirect:/index/preLogin.action";
		}
		this.usersService.updateUsers(users);
		return "redirect:/index/userinfo.action";
	}

	// 添加产品到购物车
	@RequestMapping("addcart.action")
	public String addcart() {
		this.front();
		if (this.getSession().getAttribute("userid") == null) {
			return "redirect:/index/preLogin.action";
		}
		String userid = (String) this.getSession().getAttribute("userid");
		Cart cart = new Cart();
		cart.setJiancaiid(getRequest().getParameter("goodsid"));
		cart.setNum(getRequest().getParameter("num"));
		cart.setPrice(getRequest().getParameter("price"));
		cart.setUsersid(userid);
		this.cartService.insertCart(cart);
		return "redirect:/index/cart.action";
	}

	// 查看购物车
	@RequestMapping("cart.action")
	public String cart() {
		this.front();
		if (this.getSession().getAttribute("userid") == null) {
			return "redirect:/index/preLogin.action";
			file.transferTo(targetFile);
		} catch (Exception e) {
			e.printStackTrace();
		}
		model.addAttribute("imageFileName", fileName);
		return "savefile";
	}
}

/**
 * Action 基类
 */
@Controller
public class BaseAction {

	/* 日志 */
	protected final Log log = LogFactory.getLog(getClass());

	/* 获取基本环境 */
	public Map<String, String[]> getParameters() {// 封装为Map的requestParameters
		ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
		return attrs.getRequest().getParameterMap();
	}

	public HttpServletRequest getRequest() {
		ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
		return attrs.getRequest();
	}

	public HttpSession getSession() {
		HttpSession session = null;
		try {
			session = this.getRequest().getSession();
		} catch (Exception e) {
		}
		return session;
	}
name = null;
cond = null;
return "admin/queryusers";
}

// 按主键查询数据
@RequestMapping("getUsersById.action")
public String getUsersById(String id ) {
Users users = this.usersService.getUsersById(id);
this.getRequest().setAttribute("users", users);
return "admin/editusers";
}

public UsersService getUsersService() { return usersService; }

public void setUsersService(UsersService usersService) { this.usersService = usersService; }

}

//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/cate", produces = "text/plain;charset=utf-8")
public class CateAction extends BaseAction {
	// 注入Service 由于标签的存在 所以不需要getter setter
	@Autowired
	@Resource
	private CateService cateService;

	// 准备添加数据
	@RequestMapping("createCate.action")
	public String createCate() {
		return "admin/addcate";
	}

	// 添加数据
			if ("contents".equals(cond)) {
				jiancai.setContents(name);
			}
		}

		List<String> nameList = new ArrayList<String>();
		List<String> valueList = new ArrayList<String>();
		nameList.add(cond);
		valueList.add(name);
		PageHelper.getPage(this.jiancaiService.getJiancaiByLike(jiancai), "jiancai", nameList, valueList, 10, number, this.getRequest(), "query");
		name = null;
		cond = null;
		return "admin/queryjiancai";
	}

	// 按主键查询数据
	@RequestMapping("getJiancaiById.action")
	public String getJiancaiById(String id) {
		Jiancai jiancai = this.jiancaiService.getJiancaiById(id);
		this.getRequest().setAttribute("jiancai", jiancai);
		List<Cate> cateList = this.cateService.getAllCate();
		this.getRequest().setAttribute("cateList", cateList);
		return "admin/editjiancai";
	}

	public JiancaiService getJiancaiService() {
		return jiancaiService;
	}

	public void setJiancaiService(JiancaiService jiancaiService) {
		this.jiancaiService = jiancaiService;
	}

}

	}

	// 显示全部数据
	@RequestMapping("getAllCart.action")
	public String getAllCart(String number) {
		List<Cart> cartList = this.cartService.getAllCart();
		PageHelper.getPage(cartList, "cart", null, null, 10, number, this.getRequest(), null);
		return "admin/listcart";
	}

	// 按条件查询数据 (模糊查询)
	@RequestMapping("queryCartByCond.action")
	public String queryCartByCond(String cond, String name, String number) {
		Cart cart = new Cart();
		if (cond != null) {
			if ("username".equals(cond)) {
				cart.setUsername(name);
			}
			if ("jiancainame".equals(cond)) {
				cart.setJiancainame(name);
			}
			if ("num".equals(cond)) {
				cart.setNum(name);
			}
			if ("price".equals(cond)) {
				cart.setPrice(name);
			}
		}

		List<String> nameList = new ArrayList<String>();
		List<String> valueList = new ArrayList<String>();
		nameList.add(cond);
		valueList.add(name);
		PageHelper.getPage(this.cartService.getCartByLike(cart), "cart", nameList, valueList, 10, number, this.getRequest(), "query");
		name = null;
		cond = null;
		return "admin/querycart";
	}

	// 按主键查询数据
	@RequestMapping("getCartById.action")
	public String getCartById(String id) {
		Cart cart = this.cartService.getCartById(id);
		this.getRequest().setAttribute("cart", cart);
		List<Users> usersList = this.usersService.getAllUsers();
		this.getRequest().setAttribute("usersList", usersList);
		List<Jiancai> jiancaiList = this.jiancaiService.getAllJiancai();
		this.getRequest().setAttribute("jiancaiList", jiancaiList);
		return "admin/editcart";
	}

	public CartService getCartService() {
		return cartService;
	}
		cart.setUsersid(userid);
		this.cartService.insertCart(cart);
		return "redirect:/index/cart.action";
	}

	// 查看购物车
	@RequestMapping("cart.action")
	public String cart() {
		this.front();
		if (this.getSession().getAttribute("userid") == null) {
			return "redirect:/index/preLogin.action";
		}
		String userid = (String) this.getSession().getAttribute("userid");
		Cart cart = new Cart();
		cart.setUsersid(userid);
		List<Cart> cartList = this.cartService.getCartByCond(cart);
		this.getRequest().setAttribute("cartList", cartList);
		return "users/cart";
	}

	// 删除购物车中的产品
	@RequestMapping("deletecart.action")
	public String deletecart(String id) {
		this.front();
		if (this.getSession().getAttribute("userid") == null) {
			return "redirect:/index/preLogin.action";
		}
		this.cartService.deleteCart(id);
		return "redirect:/index/cart.action";
	}

	// 准备结算
	@RequestMapping("preCheckout.action")
	public String preCheckout() {
		this.front();
		if (this.getSession().getAttribute("userid") == null) {
			return "redirect:/index/preLogin.action";
		}
		String userid = (String) this.getSession().getAttribute("userid");
		Cart cart = new Cart();
		cart.setUsersid(userid);
		try {
			file.transferTo(targetFile);
		} catch (Exception e) {
			e.printStackTrace();
		}
		model.addAttribute("imageFileName", fileName);
		return "savefile";
	}
}

/**
 * Action 基类
 */
@Controller
public class BaseAction {

	/* 日志 */
	protected final Log log = LogFactory.getLog(getClass());

	/* 获取基本环境 */
	public Map<String, String[]> getParameters() {// 封装为Map的requestParameters
		ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
		return attrs.getRequest().getParameterMap();
	}

	public HttpServletRequest getRequest() {
		ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
		return attrs.getRequest();
	}

	public HttpSession getSession() {
		HttpSession session = null;
		try {
		List<Article> tempList = this.articleService.getAllArticle();
		int pageNumber = tempList.size();
		int maxPage = pageNumber;
		if (maxPage % 12 == 0) {
			maxPage = maxPage / 12;
		} else {
			maxPage = maxPage / 12 + 1;
		}
		if (number == null) {
			number = "0";
		}
		int start = Integer.parseInt(number) * 12;
		int over = (Integer.parseInt(number) + 1) * 12;
		int count = pageNumber - over;
		if (count <= 0) {
			over = pageNumber;
		}
		for (int i = start; i < over; i++) {
			Article x = tempList.get(i);
			articleList.add(x);
		}
		String html = "";
		StringBuffer buffer = new StringBuffer();
		buffer.append("&nbsp;&nbsp;共为");
		buffer.append(maxPage);
		buffer.append("页&nbsp; 共有");
		buffer.append(pageNumber);
		buffer.append("条&nbsp; 当前为第");
		buffer.append((Integer.parseInt(number) + 1));
		buffer.append("页 &nbsp;");
		if ((Integer.parseInt(number) + 1) == 1) {
			buffer.append("首页");
		} else {
			buffer.append("<a href=\"index/article.action?number=0\">首页</a>");
		}
		buffer.append("&nbsp;&nbsp;");
		if ((Integer.parseInt(number) + 1) == 1) {
			buffer.append("上一页");
		} else {
			buffer.append("<a href=\"index/article.action?number=" + (Integer.parseInt(number) - 1) + "\">上一页</a>");
		}
		buffer.append("&nbsp;&nbsp;");
		if (maxPage <= (Integer.parseInt(number) + 1)) {
		return "admin/listcity";
	}

	// 按条件查询数据 (模糊查询)
	@RequestMapping("queryCityByCond.action")
	public String queryCityByCond(String cond, String name, String number) {
		City city = new City();
		if (cond != null) {
			if ("cityname".equals(cond)) {
				city.setCityname(name);
			}
		}

		List<String> nameList = new ArrayList<String>();
		List<String> valueList = new ArrayList<String>();
		nameList.add(cond);
		valueList.add(name);
		PageHelper.getPage(this.cityService.getCityByLike(city), "city", nameList, valueList, 10, number, this.getRequest(), "query");
		name = null;
		cond = null;
		return "admin/querycity";
	}

	// 按主键查询数据
	@RequestMapping("getCityById.action")
	public String getCityById(String id) {
		City city = this.cityService.getCityById(id);
		this.getRequest().setAttribute("city", city);
		return "admin/editcity";
	}

	public CityService getCityService() {
		return cityService;
	}

	public void setCityService(CityService cityService) {
		this.cityService = cityService;
	}

}

	@RequestMapping("register.action")
	public String register(Users users) {
		this.front();
		Users u = new Users();
		u.setUsername(users.getUsername());
		List<Users> usersList = this.usersService.getUsersByCond(u);
		if (usersList.size() == 0) {
			users.setRegdate(VeDate.getStringDateShort());
			this.usersService.insertUsers(users);
		} else {
			this.getSession().setAttribute("message", "用户名已存在");
			return "redirect:/index/preReg.action";
		}

		return "redirect:/index/preLogin.action";
	}

	// 退出登录
	@RequestMapping("exit.action")
	public String exit() {
		this.front();
		this.getSession().removeAttribute("userid");
		this.getSession().removeAttribute("username");
		this.getSession().removeAttribute("users");
		return "index";
	}

	// 准备修改密码
	@RequestMapping("prePwd.action")
	public String prePwd() {
		this.front();
		if (this.getSession().getAttribute("userid") == null) {
			return "redirect:/index/preLogin.action";
		}
		return "users/editpwd";
	}

	// 修改密码
	@RequestMapping("editpwd.action")
	public String editpwd() {
		this.front();
		if (this.getSession().getAttribute("userid") == null) {
			return "redirect:/index/preLogin.action";
		}
		String userid = (String) this.getSession().getAttribute("userid");
		String password = this.getRequest().getParameter("password");
		String repassword = this.getRequest().getParameter("repassword");
		Users users = this.usersService.getUsersById(userid);
		if (password.equals(users.getPassword())) {
			users.setPassword(repassword);
			this.usersService.updateUsers(users);
	// 批量删除数据
	@RequestMapping("deleteDetailsByIds.action")
	public String deleteDetailsByIds() {
		String[] ids = this.getRequest().getParameterValues("detailsid");
		for (String detailsid : ids) {
			this.detailsService.deleteDetails(detailsid);
		}
		return "redirect:/details/getAllDetails.action";
	}

	// 更新数据
	@RequestMapping("updateDetails.action")
	public String updateDetails(Details details) {
		this.detailsService.updateDetails(details);
		return "redirect:/details/getAllDetails.action";
	}

	// 显示全部数据
	@RequestMapping("getAllDetails.action")
	public String getAllDetails(String number) {
		List<Details> detailsList = this.detailsService.getAllDetails();
		PageHelper.getPage(detailsList, "details", null, null, 10, number, this.getRequest(), null);
		return "admin/listdetails";
	}

	// 按条件查询数据 (模糊查询)
	@RequestMapping("queryDetailsByCond.action")
	public String queryDetailsByCond(String cond, String name, String number) {
		Details details = new Details();
		if (cond != null) {
			if ("ordercode".equals(cond)) {
				details.setOrdercode(name);
			}
			if ("jiancaiid".equals(cond)) {
				details.setJiancaiid(name);
			}
			if ("num".equals(cond)) {
				details.setNum(name);
			}
			if ("price".equals(cond)) {
				details.setPrice(name);
			}
			if ("cityid".equals(cond)) {
				details.setCityid(name);
			}
			if ("peihuoid".equals(cond)) {
				details.setPeihuoid(name);
			}
			if ("viewdate".equals(cond)) {
				details.setViewdate(name);
			}
		}

		List<String> nameList = new ArrayList<String>();
	@RequestMapping("getArticleById.action")
	public String getArticleById(String id) {
		Article article = this.articleService.getArticleById(id);
		this.getRequest().setAttribute("article", article);
		return "admin/editarticle";
	}

	public ArticleService getArticleService() {
		return articleService;
	}

	public void setArticleService(ArticleService articleService) {
		this.articleService = articleService;
	}

}

//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/users" , produces = "text/plain;charset=utf-8")
public class UsersAction extends BaseAction {
// 注入Service 由于标签的存在 所以不需要getter setter
@Autowired
@Resource
private UsersService usersService;

// 准备添加数据
@RequestMapping("createUsers.action")
public String createUsers() {
return "admin/addusers";
}
// 添加数据
@RequestMapping("addUsers.action")
public String addUsers(Users users) {
users.setRegdate(VeDate.getStringDateShort());
this.usersService.insertUsers(users);
return "redirect:/users/createUsers.action";
}

// 通过主键删除数据

//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/cate", produces = "text/plain;charset=utf-8")
public class CateAction extends BaseAction {
	// 注入Service 由于标签的存在 所以不需要getter setter
	@Autowired
	@Resource
	private CateService cateService;

	// 准备添加数据
	@RequestMapping("createCate.action")
	public String createCate() {
		return "admin/addcate";
	}

	// 添加数据
	@RequestMapping("addCate.action")
	public String addCate(Cate cate) {
		cate.setAddtime(VeDate.getStringDateShort());
		this.cateService.insertCate(cate);
		return "redirect:/cate/createCate.action";
	}

	// 通过主键删除数据
	@RequestMapping("deleteCate.action")
	public String deleteCate(String id) {
		this.cateService.deleteCate(id);
		return "redirect:/cate/getAllCate.action";
	}

	// 批量删除数据
	@RequestMapping("deleteCateByIds.action")
	public String deleteCateByIds() {
		String[] ids = this.getRequest().getParameterValues("cateid");
		for (String cateid : ids) {
			this.cateService.deleteCate(cateid);
	@RequestMapping("createArticle.action")
	public String createArticle() {
		return "admin/addarticle";
	}

	// 添加数据
	@RequestMapping("addArticle.action")
	public String addArticle(Article article) {
		article.setAddtime(VeDate.getStringDateShort());
		article.setHits("0");
		this.articleService.insertArticle(article);
		return "redirect:/article/createArticle.action";
	}

	// 通过主键删除数据
	@RequestMapping("deleteArticle.action")
	public String deleteArticle(String id) {
		this.articleService.deleteArticle(id);
		return "redirect:/article/getAllArticle.action";
	}

	// 批量删除数据
	@RequestMapping("deleteArticleByIds.action")
	public String deleteArticleByIds() {
		String[] ids = this.getRequest().getParameterValues("articleid");
		for (String articleid : ids) {
			this.articleService.deleteArticle(articleid);
		}
		return "redirect:/article/getAllArticle.action";
	}

	// 更新数据
	@RequestMapping("updateArticle.action")
	public String updateArticle(Article article) {
		this.articleService.updateArticle(article);
		return "redirect:/article/getAllArticle.action";
	}

	// 显示全部数据
	@RequestMapping("getAllArticle.action")
	public String getAllArticle(String number) {
		List<Article> articleList = this.articleService.getAllArticle();
		PageHelper.getPage(articleList, "article", null, null, 10, number, this.getRequest(), null);

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

;