基于springboot农产品交易商城源码和论文(管理员 商家 用户三种角色
摘 要
伴随着互联网技术的进步,各种电商平台也如雨后 春笋不断涌现。一个好的电商平台应该具有用户体验度高,用户信息安全等特点, 从而可以满足更多的用户需求。现有的电商平台虽然在不断完善,但仍然存在着 不少问题。本设计是一个基于SSM框架开发的农产品商城项目,在较好地实现传 统电商平台的基础上又有创新和改善之处,比如分层搭建的设计思想,md5加密 算法的改进以及设计更为友好的操作界面等,以更好地服务大众。
本农产品商城网站以IDEA+mysql为开发环境,JSP+CSS+JavaScript为页面编辑语言,springboot+mybatis为后台编辑语言来设计开发,开发一个农产品商城正是为了企业独立开发的目的。J2EE体系的农产品商城 具备很高的安全性和稳定性,以及更加出色的可扩展性和跨平台特点。在国外 J2EE 已经成为开发电子商务平台的主流技术,本文研发的农产品商城系统使消费者进行购物时,不但农产品推荐更为符合消费者的消 费习惯,且农产品的质量安全以及用户个人信息能够得到有效保障,提升了消费者的购物体验,本系统主要设计用户选购,加入购物车,下单等功能,当然对应的有一个后台系统管理,主要是对前端即用户端的一个数据的支持管理,只有管理员角色才可以登陆。
本文基于springboot mybatis框架完整的实现了一个农产品商城系统,可以为用户提供购买农产品、等多个功能。从测试结果来看,系统完整实现了所需功能,而且具有一定的 稳定性和可靠性,并能够为用户提供良好的用户体验。总之,本系统基本符合客户的 需求,并达到了预期的目标。
【586】基于springboot农产品交易商城源码和论文(管理员 商家 用户三种角色
关键词:农产品商城 idea mysql springboot
Abstract
With the progress of Internet technology, various e-commerce platforms have sprung up. A good e-commerce platform should have the characteristics of high user experience and user information security, so as to meet more user needs. Although the existing e-commerce platform is constantly improving, there are still many problems. This design is an e-mall project developed based on SSM framework. On the basis of better realizing the traditional e-commerce platform, there are also innovations and improvements, such as the design idea of layered construction, the improvement of MD5 encryption algorithm and the design of a more friendly operation interface, so as to better serve the public.
This online mall website is designed and developed with idea + MySQL as the development environment, JSP + CSS + JavaScript as the page editing language and springboot + mybatis as the background editing language. Developing an electronic mall is just for the purpose of independent development of enterprises. The e-mall based on J2EE system has high security and stability, as well as better scalability and cross platform characteristics. In foreign countries, J2EE has become the mainstream technology for developing e-commerce platform. The online mall system developed in this paper not only makes consumers' commodity recommendation more in line with consumers' consumption habits, but also effectively ensures the quality and safety of commodities and users' personal information, and improves consumers' shopping experience. This system is mainly designed for users to purchase, Add shopping cart, order and other functions. Of course, there is a background system management corresponding to it, which mainly supports and manages the data of the front end, that is, the user end. Only the administrator role can log in。
Based on the framework of springboot mybatis, this paper completely implements an online mall system, which can provide users with many functions, such as purchasing goods and so on. From the test results, the system has completely realized the required functions, has certain stability and reliability, and can provide users with a good user experience. In short, the system basically meets the needs of customers and achieves the expected goal。
Key words: shop Idea mysql springboot
package com.shop.controller.admin;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shop.entity.*;
import com.shop.entity.*;
import com.shop.service.GoodsService;
import com.shop.service.OrderService;
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 javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
@Controller
@RequestMapping("/admin/order")
public class AdminOrderController {
@Autowired
private OrderService orderService;
@Autowired
private GoodsService goodsService;
@RequestMapping("/send")
public String sendOrder(@RequestParam(value = "page",defaultValue = "1")Integer pn, Model model, HttpSession session) {
User user = (User) session.getAttribute("user");
//一页显示几个数据
PageHelper.startPage(pn, 10);
//查询未发货订单
OrderExample orderExample = new OrderExample();
orderExample.or().andIssendEqualTo(false);
List<Order> orderArrayList= orderService.selectOrderByExample(orderExample);
List<Order> orderList = new ArrayList<>();
for (Order order:orderArrayList) {
if(order.getShangjiaId()==user.getUserid()){
orderList.add(order);
}
}
model.addAttribute("sendOrder", orderList);
model.addAttribute("sendOrder", orderList);
//查询该订单中的商品
for (int i = 0; i < orderList.size(); i++) {
//获取订单项中的goodsid
Order order = orderList.get(i);
OrderItemExample orderItemExample = new OrderItemExample();
orderItemExample.or().andOrderidEqualTo(order.getOrderid());
List<OrderItem> orderItemList = orderService.getOrderItemByExample(orderItemExample);
List<Integer> goodsIdList = new ArrayList<>();
List<Goods> goodsList = new ArrayList<>();
for (OrderItem orderItem : orderItemList) {
// goodsIdList.add(orderItem.getGoodsid());
Goods goods = goodsService.selectById(orderItem.getGoodsid());
goods.setNum(orderItem.getNum());
goodsList.add(goods);
}
//根据goodsid查询商品
/*GoodsExample goodsExample = new GoodsExample();
goodsExample.or().andGoodsidIn(goodsIdList);
List<Goods> goodsList = goodsService.selectByExample(goodsExample);*/
order.setGoodsInfo(goodsList);
//查询地址
Address address = orderService.getAddressByKey(order.getAddressid());
order.setAddress(address);
orderList.set(i, order);
}
//显示几个页号
PageInfo page = new PageInfo(orderList,5);
model.addAttribute("pageInfo", page);
return "adminAllOrder";
}
@RequestMapping("/sendGoods")
public String sendGoods(Integer orderid, HttpSession session) {
Order order = new Order();
order.setOrderid(orderid);
order.setIssend(true);
orderService.updateOrderByKey(order);
return "redirect:/admin/order/send";
}
@RequestMapping("/receiver")
public String receiveOrder(@RequestParam(value = "page",defaultValue = "1")Integer pn, Model model, HttpSession session) {
User user = (User) session.getAttribute("user");
//一页显示几个数据
PageHelper.startPage(pn, 2);
//查询未收货订单
OrderExample orderExample = new OrderExample();
orderExample.or().andIssendEqualTo(true).andIsreceiveEqualTo(false);
List<Order> orderArrayList= orderService.selectOrderByExample(orderExample);
List<Order> orderList = new ArrayList<>();
for (Order order:orderArrayList) {
if(order.getShangjiaId()==user.getUserid()){
orderList.add(order);
}
}
model.addAttribute("sendOrder", orderList);
//查询该订单中的商品
for (int i = 0; i < orderList.size(); i++) {
//获取订单项中的goodsid
Order order = orderList.get(i);
OrderItemExample orderItemExample = new OrderItemExample();
orderItemExample.or().andOrderidEqualTo(order.getOrderid());
List<OrderItem> orderItemList = orderService.getOrderItemByExample(orderItemExample);
List<Integer> goodsIdList = new ArrayList<>();
/*for (OrderItem orderItem : orderItemList) {
goodsIdList.add(orderItem.getGoodsid());
}
*/
List<Goods> goodsList = new ArrayList<>();
for (OrderItem orderItem : orderItemList) {
// goodsIdList.add(orderItem.getGoodsid());
Goods goods = goodsService.selectById(orderItem.getGoodsid());
goods.setNum(orderItem.getNum());
goodsList.add(goods);
}
//根据goodsid查询商品
/* GoodsExample goodsExample = new GoodsExample();
goodsExample.or().andGoodsidIn(goodsIdList);
List<Goods> goodsList = goodsService.selectByExample(goodsExample);*/
order.setGoodsInfo(goodsList);
//查询地址
Address address = orderService.getAddressByKey(order.getAddressid());
order.setAddress(address);
orderList.set(i, order);
}
//显示几个页号
PageInfo page = new PageInfo(orderList,5);
model.addAttribute("pageInfo", page);
return "adminOrderReceive";
}
@RequestMapping("/complete")
public String completeOrder(@RequestParam(value = "page", defaultValue = "1") Integer pn, Model model, HttpSession session) {
User user = (User) session.getAttribute("user");
PageHelper.startPage(pn, 2);
//查询已完成订单
OrderExample orderExample = new OrderExample();
orderExample.or().andIssendEqualTo(true).andIsreceiveEqualTo(true).andIscompleteEqualTo(true);
List<Order> orderArrayList= orderService.selectOrderByExample(orderExample);
List<Order> orderList = new ArrayList<>();
for (Order order:orderArrayList) {
if(order.getShangjiaId()==user.getUserid()){
orderList.add(order);
}
}
model.addAttribute("sendOrder", orderList);
model.addAttribute("sendOrder", orderList);
//查询该订单中的商品
for (int i = 0; i < orderList.size(); i++) {
//获取订单项中的goodsid
Order order = orderList.get(i);
OrderItemExample orderItemExample = new OrderItemExample();
orderItemExample.or().andOrderidEqualTo(order.getOrderid());
List<OrderItem> orderItemList = orderService.getOrderItemByExample(orderItemExample);
List<Integer> goodsIdList = new ArrayList<>();
/*for (OrderItem orderItem : orderItemList) {
goodsIdList.add(orderItem.getGoodsid());
}*/
List<Goods> goodsList = new ArrayList<>();
for (OrderItem orderItem : orderItemList) {
// goodsIdList.add(orderItem.getGoodsid());
Goods goods = goodsService.selectById(orderItem.getGoodsid());
goods.setNum(orderItem.getNum());
goodsList.add(goods);
}
//根据goodsid查询商品
/*GoodsExample goodsExample = new GoodsExample();
goodsExample.or().andGoodsidIn(goodsIdList);
List<Goods> goodsList = goodsService.selectByExample(goodsExample);*/
order.setGoodsInfo(goodsList);
//查询地址
Address address = orderService.getAddressByKey(order.getAddressid());
order.setAddress(address);
orderList.set(i, order);
}
//显示几个页号
PageInfo page = new PageInfo(orderList, 5);
model.addAttribute("pageInfo", page);
return "adminOrderComplete";
}
}
package com.shop.controller.admin;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shop.entity.*;
import com.shop.entity.*;
import com.shop.service.CateService;
import com.shop.service.GoodsService;
import com.shop.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
@Controller
@RequestMapping("/admin/goods")
public class GoodsController {
@Autowired
private GoodsService goodsService;
@RequestMapping("/showjson")
@ResponseBody
public Msg getAllGoods(@RequestParam(value = "page", defaultValue = "1") Integer pn, HttpServletResponse response, Model model, HttpSession session) {
Admin admin = (Admin) session.getAttribute("admin");
if (admin == null) {
return Msg.fail("请先登录");
}
//一页显示几个数据
PageHelper.startPage(pn, 10);
List<Goods> employees = goodsService.selectByExample(new GoodsExample());
for(Goods good:employees){
System.out.println(good);
}
//显示几个页号
PageInfo page = new PageInfo(employees, 5);
model.addAttribute("pageInfo", page);
return Msg.success("查询成功!").add("pageInfo", page);
}
@RequestMapping("/show")
public String goodsManage(@RequestParam(value = "page", defaultValue = "1") Integer pn, HttpServletResponse response, Model model, HttpSession session) throws IOException {
Admin admin = (Admin) session.getAttribute("admin");
if (admin == null) {
return "redirect:/admin/login";
}
List<Category> categoryList = cateService.selectByExample(new CategoryExample());
model.addAttribute("categoryList", categoryList);
return "adminAllGoods";
}
@RequestMapping("/add")
public String showAdd(@ModelAttribute("succeseMsg") String msg, Model model, HttpSession session) {
if (!msg.equals("")) {
model.addAttribute("msg", msg);
}
List<Category> categoryList = cateService.selectByExample(new CategoryExample());
model.addAttribute("categoryList", categoryList);
//还需要查询分类传给addGoods页面
return "addGoods";
}
@RequestMapping(value = "/update", method = RequestMethod.POST)
@ResponseBody
public Msg updateGoods(Goods goods, HttpSession session) {
/* goods.setGoodsid(goodsid);*/
goodsService.updateGoodsById(goods);
return Msg.success("更新成功!");
}
@RequestMapping(value = "/delete/{goodsid}", method = RequestMethod.DELETE)
@ResponseBody
public Msg deleteGoods(@PathVariable("goodsid") Integer goodsid) {
goodsService.deleteGoodsById(goodsid);
return Msg.success("删除成功!");
}
@RequestMapping("/addGoodsSuccess")
public String addGoods(Goods goods,
@RequestParam MultipartFile fileToUpload,
HttpServletRequest request,
HttpServletResponse response,
RedirectAttributes redirectAttributes) throws IOException {
/*goods.setCategory(1);*/
HttpSession session = request.getSession();
User user = (User) session.getAttribute("user");
goods.setUptime(new Date());
goods.setActivityid(1);
goods.setUserId(user.getUserid());
//上传图片
String name = UUID.randomUUID().toString();
String newFileName = name + ".jpg";
File newFile = new File(request.getServletContext().getRealPath("/image"), newFileName);
newFile.getParentFile().mkdirs();
goodsService.addGoods(goods);
try {
fileToUpload.transferTo(newFile);
goodsService.addImagePath(new ImagePath(null, goods.getGoodsid(), "image/"+newFileName));
} catch (Exception e) {
e.printStackTrace();
goodsService.deleteGoodsById( goods.getGoodsid());
redirectAttributes.addFlashAttribute("succeseMsg", "添加失败,图片大小不能超过1M!");
return "redirect:/admin/goods/add";
}
redirectAttributes.addFlashAttribute("succeseMsg", "商品添加成功!");
return "redirect:/admin/goods/add";
}
@RequestMapping("/addCategory")
public String addcategory(@ModelAttribute("succeseMsg") String msg, Model model, HttpSession session) {
Admin admin = (Admin) session.getAttribute("admin");
if (admin == null) {
return "redirect:/admin/login";
}
CategoryExample categoryExample = new CategoryExample();
categoryExample.or();
List<Category> categoryList;
categoryList = cateService.selectByExample(categoryExample);
model.addAttribute("categoryList", categoryList);
if (!msg.equals("")) {
model.addAttribute("msg", msg);
}
return "addCategory";
}
@Autowired
private CateService cateService;
@RequestMapping("/addCategoryResult")
public String addCategoryResult(Category category, Model addCategoryResult, RedirectAttributes redirectAttributes) {
List<Category> categoryList = new ArrayList<>();
CategoryExample categoryExample = new CategoryExample();
categoryExample.or().andCatenameEqualTo(category.getCatename());
categoryList = cateService.selectByExample(categoryExample);
if (!categoryList.isEmpty()) {
redirectAttributes.addAttribute("succeseMsg", "分类已存在");
return "redirect:/admin/goods/addCategory";
} else {
cateService.insertSelective(category);
redirectAttributes.addFlashAttribute("succeseMsg", "分类添加成功!");
return "redirect:/admin/goods/addCategory";
}
}
@RequestMapping("/saveCate")
@ResponseBody
public Msg saveCate(Category category) {
CategoryExample categoryExample = new CategoryExample();
categoryExample.or().andCatenameEqualTo(category.getCatename());
List<Category> categoryList = cateService.selectByExample(categoryExample);
if (categoryList.isEmpty()) {
cateService.updateByPrimaryKeySelective(category);
return Msg.success("更新成功");
} else return Msg.success("名字已经存在");
}
@RequestMapping("/deleteCate")
@ResponseBody
public Msg deleteCate(Category category) {
cateService.deleteByPrimaryKey(category.getCateid());
return Msg.success("删除成功");
}
@RequestMapping("/shangjiashowjson")
@ResponseBody
public Msg shangjiashowjson(@RequestParam(value = "page", defaultValue = "1") Integer pn, HttpServletResponse response, Model model, HttpSession session) {
User user = (User) session.getAttribute("user");
//一页显示几个数据
PageHelper.startPage(pn, 10);
GoodsExample goodsExample = new GoodsExample();
GoodsExample.Criteria criteria= goodsExample.createCriteria();
List<Goods> employees = goodsService.selectByExample(goodsExample);
List<Goods> goodsList = new ArrayList<>();
for (Goods goods:employees) {
if(user.getUserid()==goods.getUserId()){
goodsList.add(goods);
}
}
//显示几个页号
PageInfo page = new PageInfo(goodsList, 5);
model.addAttribute("pageInfo", page);
return Msg.success("查询成功!").add("pageInfo", page);
}
@RequestMapping("/shangjiashow")
public String shangjiashow(@RequestParam(value = "page", defaultValue = "1") Integer pn, HttpServletResponse response, Model model, HttpSession session) throws IOException {
List<Category> categoryList = cateService.selectByExample(new CategoryExample());
model.addAttribute("categoryList", categoryList);
return "shangjiaGoods";
}
}