• SSM网上在线水果店商城超市网站平台


    作者主页:夜未央5788

     简介:Java领域优质创作者、Java项目、学习资料、技术互助

    文末获取源码

    项目介绍

    该项目为前后台项目,分为普通用户与管理员两种角色,前台普通用户登录,后台管理员登录;

    管理员角色包含以下功能:

    管理员登录,用户管理,一级分类管理,二级分类管理,水果管理,订单管理,留言管理等功能。

    用户管理包含以下功能:

    按分类查看水果,用户登录,查看商品详情,加入购物车,提交订单,查看订单,提交留言等功能。

    环境需要

    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+jQuery+Ajax

    使用说明

    1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;

    2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;

    若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;

    3. 将项目中jdbc.properties配置文件中的数据库配置改为自己的配置;

    4. 运行项目,输入localhost:8080/ 登录

    运行截图

    前台界面

     

     

     

     

     

     

     

    后台界面

     

     

     

     

     

     

     

    相关代码

    全局异常处理

    1. package com.shop.exception;
    2. import javax.servlet.http.HttpServletRequest;
    3. import javax.servlet.http.HttpServletResponse;
    4. import org.springframework.stereotype.Controller;
    5. import org.springframework.web.servlet.HandlerExceptionResolver;
    6. import org.springframework.web.servlet.ModelAndView;
    7. public class golbalException implements HandlerExceptionResolver {
    8. public ModelAndView resolveException(HttpServletRequest request,
    9. HttpServletResponse response, Object handler, Exception ex) {
    10. response.setHeader("content-type", "text/html;charset=UTF-8");
    11. response.setHeader("refresh", "5;url=/shop/index.action");
    12. zdyException exception =null;
    13. if(ex instanceof zdyException){
    14. exception=(zdyException)ex;
    15. }else{
    16. exception.setMessage("发生了未知异常");
    17. }
    18. ModelAndView modelAndView = new ModelAndView();
    19. modelAndView.addObject("errorMessage",exception.getMessage()+"系统将在5秒之后跳转到首页......");
    20. modelAndView.setViewName("error");
    21. return modelAndView;
    22. }
    23. }

    自定义异常处理

    1. package com.shop.exception;
    2. public class zdyException extends Exception{
    3. private String message;
    4. public zdyException(String message) {
    5. super();
    6. this.message = message;
    7. }
    8. public String getMessage() {
    9. return message;
    10. }
    11. public void setMessage(String message) {
    12. this.message = message;
    13. }
    14. }

    编码拦截

    1. package com.shop.interceptor;
    2. import java.util.Iterator;
    3. import javax.servlet.http.HttpServletRequest;
    4. import javax.servlet.http.HttpServletResponse;
    5. import org.springframework.web.servlet.HandlerInterceptor;
    6. import org.springframework.web.servlet.ModelAndView;
    7. public class EncodingInterceptor implements HandlerInterceptor {
    8. @Override
    9. public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
    10. Object arg2) throws Exception {
    11. response.setContentType("text/html;charset=UTF-8");
    12. /*String method = request.getMethod();
    13. if (method.equalsIgnoreCase("post")) {
    14. request.setCharacterEncoding("utf-8");
    15. } else {
    16. // new String(request.getParameter("name").getBytes("iso8859-1"),"utf-8");
    17. Iterator iter = request.getParameterMap().values().iterator();
    18. while (iter.hasNext()) {
    19. String[] parames = (String[]) iter.next();
    20. for (int i = 0; i < parames.length; i++) {
    21. parames[i] = new String(parames[i].getBytes("iso8859-1"),
    22. "utf-8");// 此处utf-8与页面编码一样
    23. }
    24. }
    25. }*/
    26. return true;
    27. }
    28. @Override
    29. public void postHandle(HttpServletRequest request, HttpServletResponse response,
    30. Object arg2, ModelAndView arg3) throws Exception {
    31. }
    32. @Override
    33. public void afterCompletion(HttpServletRequest request,
    34. HttpServletResponse arg1, Object arg2, Exception arg3)
    35. throws Exception {
    36. }
    37. }

    权限拦截

    1. package com.shop.interceptor;
    2. import javax.servlet.http.HttpServletRequest;
    3. import javax.servlet.http.HttpServletResponse;
    4. import org.springframework.stereotype.Controller;
    5. import org.springframework.web.servlet.HandlerInterceptor;
    6. import org.springframework.web.servlet.ModelAndView;
    7. import com.shop.po.Adminuser;
    8. @Controller
    9. public class PrivilageInterceptor implements HandlerInterceptor{
    10. @Override
    11. public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
    12. Object object) throws Exception {
    13. String uri = request.getRequestURI();
    14. if(uri.indexOf("admin.action")>=0){
    15. return true;
    16. }
    17. Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
    18. if(adminuserLogin!=null){
    19. return true ;
    20. }
    21. request.getRequestDispatcher("/WEB-INF/jsp/admin/index.jsp").forward(request, response);
    22. return true;
    23. }
    24. @Override
    25. public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
    26. Object arg2, ModelAndView arg3) throws Exception {
    27. }
    28. @Override
    29. public void afterCompletion(HttpServletRequest arg0,
    30. HttpServletResponse arg1, Object arg2, Exception arg3)
    31. throws Exception {
    32. }
    33. }

    邮箱处理工具类

    1. package com.shop.Utils;
    2. import java.util.Properties;
    3. import javax.mail.Authenticator;
    4. import javax.mail.Message;
    5. import javax.mail.MessagingException;
    6. import javax.mail.PasswordAuthentication;
    7. import javax.mail.Session;
    8. import javax.mail.Transport;
    9. import javax.mail.internet.AddressException;
    10. import javax.mail.internet.InternetAddress;
    11. import javax.mail.internet.MimeMessage;
    12. import javax.mail.internet.MimeMessage.RecipientType;
    13. public class MailUtils {
    14. // email是邮箱地址 emailMsg是发送给邮箱的内容
    15. public static void sendMail(String email, String emailMsg)
    16. throws AddressException, MessagingException {
    17. // 1.创建一个程序与邮件服务器会话对象 Session
    18. Properties props = new Properties();
    19. props.setProperty("mail.host", "localhost");
    20. // 创建验证器
    21. Authenticator auth = new Authenticator() {
    22. public PasswordAuthentication getPasswordAuthentication() {
    23. return new PasswordAuthentication("service@shop.com", "111");
    24. }
    25. };
    26. Session session = Session.getInstance(props, auth);
    27. Message message = new MimeMessage(session);
    28. message.setFrom(new InternetAddress("service@shop.com")); // 设置发送者
    29. message.setRecipient(RecipientType.TO, new InternetAddress(email)); // 设置发送方式与接收者
    30. message.setSubject("用户激活");
    31. message.setContent(emailMsg, "text/html;charset=utf-8");
    32. Transport.send(message);
    33. }
    34. }

    分页处理

    1. package com.shop.Utils;
    2. import java.util.List;
    3. public class PageBean {
    4. private int page;//第几页
    5. private int totlePage;//一共多少页
    6. private int limitPage;//每页多少个
    7. private List list;//目标集合
    8. public int getPage() {
    9. return page;
    10. }
    11. public void setPage(int page) {
    12. this.page = page;
    13. }
    14. public int getTotlePage() {
    15. return totlePage;
    16. }
    17. public void setTotlePage(int totlePage) {
    18. this.totlePage = totlePage;
    19. }
    20. public int getLimitPage() {
    21. return limitPage;
    22. }
    23. public void setLimitPage(int limitPage) {
    24. this.limitPage = limitPage;
    25. }
    26. public List getList() {
    27. return list;
    28. }
    29. public void setList(List list) {
    30. this.list = list;
    31. }
    32. public String toString() {
    33. return "PageBean [page=" + page + ", totlePage=" + totlePage
    34. + ", limitPage=" + limitPage + ", list=" + list + "]";
    35. }
    36. }

    UUID工具类

    1. package com.shop.Utils;
    2. import java.util.UUID;
    3. public class UUIDUtiils {
    4. public static String getUUID(){
    5. return UUID.randomUUID().toString();
    6. }
    7. }

    如果也想学习本系统,下面领取。关注并回复:164ssm

  • 相关阅读:
    1.4-JMeter插件
    enumerate内置函数的使用
    Golang标准库限流器rate使用
    (二十四)数据结构-选择排序
    C#Socket
    Linux系统创建可执行文件软链接
    7-94 求N分之一序列前N项和
    python barplot 比例bili scanpy
    debugserver+lldb连接不上的解决办法
    洛谷P4127 [AHOI2009]同类分布 题解
  • 原文地址:https://blog.csdn.net/hanyunlong1989/article/details/126446944