IDEA+Java+SSM+Mysql+JSP实现Web宠物商城系统(1)

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 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 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 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 csPageBean = categorySecondService

.adminCategorySecond_findAllByPage(page);

/*List 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 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 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 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 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 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 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 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”;

}

}

ajaxController


package com.shop.controller;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;

import com.shop.po.User;

import com.shop.service.UserService;

@Controller

public class ajaxController {

@Autowired

private UserService userService;

@RequestMapping(“/loginFindByid”)

public void loginFindByid(HttpServletRequest request,

HttpServletResponse response, @RequestParam String username) {

response.setContentType(“text/html;charset=UTF-8”);

try {

User user = userService.loginFindByid(username);

if (user != null) {

response.getWriter().write(“可以登录”);

} else {

response.getWriter().write(“不可以登录”);

}

} catch (Exception e) {

e.printStackTrace();

}

}

@RequestMapping(“/registFindByid”)

public void registFindByid(HttpServletRequest request,

HttpServletResponse response, @RequestParam String username) {

response.setContentType(“text/html;charset=UTF-8”);

try {

User user = userService.loginFindByid(username);

if (user != null) {

response.getWriter().write(“已经被注册”);

} else {

response.getWriter().write(“可以注册”);

}

} catch (Exception e) {

e.printStackTrace();

}

}

}

cartController


package com.shop.controller;

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.Cart;

import com.shop.po.CartItem;

import com.shop.po.Product;

import com.shop.po.User;

import com.shop.service.ProductService;

@Controller

public class cartController {

@Autowired

private ProductService productService;

// 添加到购物车

@RequestMapping(“/addCart”)

public String addCart(HttpServletRequest request, @RequestParam int pid, @RequestParam int count, Model model) {

Product product = productService.finbProductByPid(pid);

// 存进一个购物项

CartItem cartItem = new CartItem();

cartItem.setCount(count);

cartItem.setProduct(product);

cartItem.setSubtotle(count * product.getShopPrice());

// 存进购物车

Cart cart = getCart(request);

cart.addCart(cartItem);

return “cart”;

}

// 查看我的购物车

@RequestMapping(“/myCart”)

public String myCart(HttpServletRequest request, Model model) {

User loginUser = (User) request.getSession().getAttribute(“loginUser”);

if (loginUser == null) {

model.addAttribute(“message”, “您还没有登录!”);

return “msg”;

}

return “cart”;

}

// 清空购物车

@RequestMapping(“/clearCart”)

public String clearCart(HttpServletRequest request) {

Cart cart = getCart(request);

cart.clearCart();

return “redirect:myCart.action”;

}

// 删除某个购物项

@RequestMapping(“/delProFromCart”)

public String delProFromCart(@RequestParam int pid, HttpServletRequest request) {

Cart cart = getCart(request);

cart.delProFromCart(pid);

return “redirect:myCart.action”;

}

public Cart getCart(HttpServletRequest request) {

Cart cart = (Cart) request.getSession().getAttribute(“cart”);

if (cart == null) {

cart = new Cart();

request.getSession().setAttribute(“cart”, cart);

}

return cart;

}

}

CategorySecondController


package com.shop.controller;

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.Utils.PageBean;

import com.shop.po.Product;

import com.shop.service.ProductService;

@Controller

public class CategorySecondController {

@Autowired

private ProductService productService;

//根据一级目录查找二级目录下面的商品(使用延迟加载但是这里不知为啥使用起来出错了)

@RequestMapping(“/findCategorySecond”)

public String findCategorySecond(HttpServletRequest request, @RequestParam int cid, Model model, @RequestParam int page) throws Exception {

request.getSession().setAttribute(“cid”, cid);

PageBean proPageBean = productService.findProductyBycid(cid, page);

model.addAttribute(“pageBean”, proPageBean);

return “category”;

}

// 根据csid来分页查询商品

@RequestMapping(“/findCategorySecond1”)

public String findCategorySecond1(@RequestParam int csid, Model model, @RequestParam int page) {

PageBean proPageBean = productService.finbProductByCsid(csid, page);

model.addAttribute(“pageBean”, proPageBean);

return “category”;

}

}

checkImgController


package com.shop.controller;

import java.awt.Color;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

import java.io.IOException;

import java.util.Random;

import javax.imageio.ImageIO;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

@Controller

public class checkImgController {

@RequestMapping(“checkImg”)

public void checkImg(HttpServletRequest request, HttpServletResponse response) throws IOException {

int width = 120;

最后

还有Java核心知识点+全套架构师学习资料和视频+一线大厂面试宝典+面试简历模板可以领取+阿里美团网易腾讯小米爱奇艺快手哔哩哔哩面试题+Spring源码合集+Java架构实战电子书+2021年最新大厂面试题。
在这里插入图片描述

egory";

}

// 根据csid来分页查询商品

@RequestMapping(“/findCategorySecond1”)

public String findCategorySecond1(@RequestParam int csid, Model model, @RequestParam int page) {

PageBean proPageBean = productService.finbProductByCsid(csid, page);

model.addAttribute(“pageBean”, proPageBean);

return “category”;

}

}

checkImgController


package com.shop.controller;

import java.awt.Color;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

import java.io.IOException;

import java.util.Random;

import javax.imageio.ImageIO;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

@Controller

public class checkImgController {

@RequestMapping(“checkImg”)

public void checkImg(HttpServletRequest request, HttpServletResponse response) throws IOException {

int width = 120;

最后

还有Java核心知识点+全套架构师学习资料和视频+一线大厂面试宝典+面试简历模板可以领取+阿里美团网易腾讯小米爱奇艺快手哔哩哔哩面试题+Spring源码合集+Java架构实战电子书+2021年最新大厂面试题。
[外链图片转存中…(img-EbObG2T9-1714299113065)]

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值