1、项目演示
DC00001基于java web+MySQL在线购物商城ssm购物系统jsp+mysql销售管理系统
2、项目功能描述
基于ssm购物商城分为用户和系统管理员角色。
用户功能:
1、系统首页、登录注册
2、用户留言
3、商品浏览、购物车
4、我的订单
5、退出系统
管理员功能:
1、系统登录
2、用户管理
3、商品一级分类、二级分类管理
4、订单管理
5、留言管理
6、退出系统
3、项目效果图(部分)
4、核心代码
package com.shop.controller;
import java.io.File;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import com.shop.Utils.PageBean;
import com.shop.Utils.UUIDUtiils;
import com.shop.po.Adminuser;
import com.shop.po.Category;
import com.shop.po.Categorysecond;
import com.shop.po.Message;
import com.shop.po.Orders;
import com.shop.po.Product;
import com.shop.po.User;
import com.shop.service.CategorySecondService;
import com.shop.service.CategoryService;
import com.shop.service.MessageService;
import com.shop.service.OrderService;
import com.shop.service.ProductService;
import com.shop.service.UserService;
@Controller
public class AdminController {
@Autowired
private UserService userService;
@Autowired
public CategoryService categoryService;
@Autowired
public CategorySecondService categorySecondService;
@Autowired
public ProductService productService;
@Autowired
private OrderService orderService;
@Autowired
private MessageService messageService;
@RequestMapping("/admin/admin_findAll")
public String admin_findAll(Model model,HttpServletRequest request) throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
List<User> userList = userService.admin_findAll();
model.addAttribute("userList", userList);
return "admin/user/list";
}
@RequestMapping("/admin/adminCategory_findAll")
public String adminCategory_findAll(Model model, HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
List<Category> categoryList = categoryService.adminbFindCategory();
/*for (Category category : categoryList) {
System.out.println(category.getCname());
}*/
model.addAttribute("categoryList", categoryList);
return "admin/category/list";
}
@RequestMapping("/admin/adminCategory_add")
public String adminCategory_add(Model model,HttpServletRequest request) throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
// List<Category> categoryList = categoryService.adminbFindCategory();
// model.addAttribute("categoryList", categoryList);
return "admin/category/add";
}
@RequestMapping("/admin/adminCategory_save")
public String adminCategory_save(@RequestParam String cname,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
Category addCategory = new Category();
addCategory.setCname(cname);
categoryService.addCategory(addCategory);
return "redirect:/admin/adminCategory_findAll.action";
}
@RequestMapping("/admin/adminCategory_edit")
public String adminCategory_delete(@RequestParam int cid, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
Category existCategory = categoryService.findCategory(cid);
model.addAttribute("existCategory", existCategory);
return "admin/category/edit";
}
@RequestMapping("/admin/adminCategory_update")
public String adminCategory_update(@RequestParam int cid,
@RequestParam String cname,HttpServletRequest request) {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
Category category = new Category();
category.setCid(cid);
category.setCname(cname);
categoryService.adminCategory_update(category);
return "redirect:/admin/adminCategory_findAll.action";
}
@RequestMapping("/admin/adminCategory_delete")
public String adminCategory_delete(@RequestParam int cid,HttpServletRequest request) throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
categorySecondService.adminCategorySecond_deleteByCid(cid);
categoryService.deleteCategoryByCid(cid);
return "redirect:/admin/adminCategory_findAll.action";
}
// admin 的二级分类的管理
@RequestMapping("/admin/adminCategorySecond_findAllByPage")
public String adminCategorySecond_findAllByPage(@RequestParam int page,Model model,HttpServletRequest request) {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
PageBean<Categorysecond> csPageBean = categorySecondService
.adminCategorySecond_findAllByPage(page);
/*List<Categorysecond> list = csPageBean.getList();
for (Categorysecond categorysecond : list) {
System.out.println(categorysecond.getCsname());
}*/
model.addAttribute("csPageBean", csPageBean);
return "admin/categorysecond/list";
}
@RequestMapping("admin/adminCategorySecond_addPage")
public String adminCategorySecond_addPage(Model model,HttpServletRequest request) throws Exception{
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
List<Category> categoryList = categoryService.adminbFindCategory();
model.addAttribute("categoryList", categoryList);
return "admin/categorysecond/add";
}
@RequestMapping("admin/adminCategorySecond_save")
public String adminCategorySecond_save(@RequestParam String csname,@RequestParam int cid,HttpServletRequest request) throws Exception{
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
Categorysecond categorysecond = new Categorysecond();
categorysecond.setCsname(csname);
categorysecond.setCid(cid);
categorySecondService.adminCategorySecond_save(categorysecond);
return "redirect:/admin/adminCategorySecond_findAllByPage.action?page=1";
}
@RequestMapping("admin/adminCategorySecond_edit")
public String adminCategorySecond_edit(@RequestParam int csid,Model model,HttpServletRequest request) throws Exception{
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
Categorysecond findByCsid = categorySecondService.findByCsid(csid);
model.addAttribute("findByCsid", findByCsid);
return "admin/categorysecond/edit";
}
@RequestMapping("admin/adminCategorySecond_update")
public String adminCategorySecond_update(@RequestParam String csname,@RequestParam int csid,HttpServletRequest request){
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
Categorysecond categorysecond = new Categorysecond();
categorysecond.setCsname(csname);
categorysecond.setCsid(csid);
categorySecondService.adminCategorySecond_update(categorysecond);
return "redirect:/admin/adminCategorySecond_findAllByPage.action?page=1";
}
@RequestMapping("admin/adminCategorySecond_delete")
public String adminCategorySecond_delete(@RequestParam int csid,HttpServletRequest request) throws Exception{
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
categorySecondService.adminCategorySecond_delete(csid);
return "redirect:/admin/adminCategorySecond_findAllByPage.action?page=1";
}
//admin的商品管理
@RequestMapping("/admin/adminProduct_findAllByPage")
public String adminProduct_findAllByPage(@RequestParam int page, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
PageBean<Product> allProPageBean = productService.findAllProduct(page);
model.addAttribute("allProPageBean", allProPageBean);
return "admin/product/list";
}
@RequestMapping("/admin/adminProduct_addPage")
public String adminProduct_addPage(Model model,HttpServletRequest request) throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
//查询出所有的二级分类
List<Categorysecond> cslist = categorySecondService.findAll();
/*for (Categorysecond categorysecond : cslist) {
System.out.println(categorysecond.getCsname());
}*/
model.addAttribute("cslist", cslist);
return "admin/product/add";
}
@RequestMapping("/admin/adminProduct_save")
public String adminProduct_save(Product product,HttpServletRequest request,MultipartFile file) throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
product.setPdate(new Date());
// 上传图片
if (file != null) {
String path = request.getServletContext().getRealPath(
"/products");
String uploadFileName = file.getOriginalFilename();
String fileName = UUIDUtiils.getUUID()+uploadFileName;
File diskFile = new File(path + "//" + fileName);
file.transferTo(diskFile);
product.setImage("products/" + fileName);
}
System.out.println(product.getImage());
productService.adminProduct_save(product);
return "redirect:/admin/adminProduct_findAllByPage.action?page=1";
}
@RequestMapping("admin/adminProduct_deletecs")
public String adminProduct_deletecs(@RequestParam int pid,HttpServletRequest request) throws Exception{
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
productService.adminProduct_deletecs(pid);
return "redirect:/admin/adminProduct_findAllByPage.action?page=1";
}
/**
* 编辑商品
*
* @param pid
* @param model
* @param request
* @return
* @throws Exception
*/
@RequestMapping("admin/adminProduct_edit")
public String adminProduct_edit(@RequestParam int pid,Model model,HttpServletRequest request) throws Exception{
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
Product product = productService.finbProductByPid(pid);
model.addAttribute("findByPid", product);
//查询出所有的二级分类
List<Categorysecond> cslist = categorySecondService.findAll();
model.addAttribute("cslist", cslist);
return "admin/product/edit";
}
@RequestMapping("/admin/adminProduct_update")
public String adminProduct_update(Product product,HttpServletRequest request,MultipartFile file) throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
product.setPdate(new Date());
// 上传图片
if (file != null) {
String path = request.getServletContext().getRealPath(
"/products");
String uploadFileName = file.getOriginalFilename();
String fileName = UUIDUtiils.getUUID()+uploadFileName;
File diskFile = new File(path + "//" + fileName);
file.transferTo(diskFile);
product.setImage("products/" + fileName);
}
productService.adminProduct_update(product);
return "redirect:/admin/adminProduct_findAllByPage.action?page=1";
}
/** 订单管理模块 **/
@RequestMapping("/admin/adminOrder_findAllByPage")
public String adminOrder_findAllByPage(@RequestParam int page, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
PageBean<Orders> allProPageBean = orderService.findAllOrderByStateAndPage(page);
model.addAttribute("pageBean", allProPageBean);
return "admin/order/list";
}
//adminOrder_findByState
@RequestMapping("/admin/adminOrder_findByState")
public String adminOrder_findByState(@RequestParam int page,@RequestParam int state, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
PageBean<Orders> allProPageBean = orderService.findAllOrderByStateAndPage(state,page);
model.addAttribute("pageBean", allProPageBean);
return "admin/order/list";
}
//订单详情
//adminOrder_findOrderItem
@RequestMapping("/admin/adminOrder_findOrderItem")
public String adminOrder_findOrderItem(@RequestParam int oid, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
Orders orderItems = orderService.findOrderByOid(oid);
model.addAttribute("orderItems", orderItems);
return "admin/order/list";
}
//更新订单状态
@RequestMapping("/admin/adminOrder_updateState")
public String adminOrder_updateState(@RequestParam int oid, @RequestParam int status, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
orderService.updateOrderStatus(oid, status);
return "redirect:/admin/adminOrder_findAllByPage.action?page=1";
}
//后台留言管理
@RequestMapping("/admin/adminMessage_findAllByPage")
public String adminMessage_findAllByPage(@RequestParam int page, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
PageBean<Message> pageBean = messageService.findAllMessageByPage(page);
model.addAttribute("pageBean", pageBean);
return "admin/message/list";
}
@RequestMapping("/admin/adminMessage_delete")
public String adminOrder_updateState(@RequestParam int messageid, Model model,HttpServletRequest request)
throws Exception {
Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
if(adminuserLogin==null){
request.getSession().setAttribute("message","对不起您还没有登录");
return "admin/index";
}
messageService.deleteMessage(messageid);
return "redirect:/admin/adminMessage_findAllByPage.action?page=1";
}
}
package com.shop.controller;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.shop.po.Category;
import com.shop.po.Product;
import com.shop.service.CategoryService;
import com.shop.service.ProductService;
@Controller
public class indexController {
@Autowired
private CategoryService categoryService;
@Autowired
private ProductService productService;
@RequestMapping("/index")
public String index(Model model,HttpServletRequest request) throws Exception {
//查询一级分类
List<Category> cList = categoryService.findCategory();
request.getSession().getServletContext().setAttribute("cList",cList);
// model.addAttribute("cList", cList);
//查询热门商品
List<Product> hList= productService.findHotProduct();
model.addAttribute("hList", hList);
//查询最新商品
List<Product> nList = productService.findNewProduct();
model.addAttribute("nList", nList);
//滚动图片专用,最多显示3个商品
List<Product> sList;
if(hList.size()>3)
{
sList = new ArrayList<Product>();
sList.add(hList.get(0));
sList.add(hList.get(1));
sList.add(hList.get(2));
model.addAttribute("sList", sList);
}
else
{
model.addAttribute("sList", hList);
}
return "index";
}
@RequestMapping("/about")
public String about(Model model,HttpServletRequest request) throws Exception {
return "about";
}
@RequestMapping("/contact")
public String contact(Model model,HttpServletRequest request) throws Exception {
return "contact";
}
@RequestMapping("/delivery")
public String delivery(Model model,HttpServletRequest request) throws Exception {
return "delivery";
}
//
@RequestMapping("/searchProduct")
public String searchProduct(@RequestParam String condition,Model model,HttpServletRequest request) throws Exception {
//查询一级分类
List<Category> cList = categoryService.findCategory();
request.getSession().getServletContext().setAttribute("cList",cList);
//查询商品
List<Product> hList= productService.findHotProduct();
model.addAttribute("hList", hList);
//搜索商品
List<Product> srList = productService.searchProduct(condition);
model.addAttribute("srList", srList);
//滚动图片专用,最多显示3个商品
List<Product> sList;
if(hList.size()>3)
{
sList = new ArrayList<Product>();
sList.add(hList.get(0));
sList.add(hList.get(1));
sList.add(hList.get(2));
model.addAttribute("sList", sList);
}
else
{
model.addAttribute("sList", hList);
}
return "searchProduct";
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<mvc:annotation-driven conversion-service="conversionService" validator="validator"></mvc:annotation-driven>
<!-- 配置一个校验器 -->
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<!-- hibernate校验器 指定了提供校验器的提供商 -->
<property name="providerClass" value="org.hibernate.validator.HibernateValidator"/>
<!-- 指定校验时资源文件 也就是发生错误显示的信息 -->
<property name="validationMessageSource" ref="messageSource"/>
</bean>
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:UserValidationMessage"/>
<property name="fileEncodings" value="utf-8"/>
<property name="cacheSeconds" value="120"/>
</bean>
<!-- 自定义参数绑定 -->
<bean id="conversionService"
class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<!-- 转换器 -->
<property name="converters">
<list>
<bean class="com.shop.controller.converters.DateConverters" />
</list>
</property>
</bean>
<context:component-scan base-package="com.shop.controller" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!--全局异常 -->
<!-- <bean class="com.shop.exception.golbalException"/> -->
<!-- 配置图片上传解析器 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize">
<value>5242880</value>
</property>
</bean>
<!--拦截器的配置 -->
<!-- <mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/admin/*.action"/>
<bean class="com.shop.interceptor.PrivilageInterceptor" />
</mvc:interceptor>
</mvc:interceptors> -->
</beans>
5、项目获取
私聊,或者通过添加名片,可获取项目资源文件