作者主页:夜未央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/ 登录
- package com.shop.exception;
-
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
-
- import org.springframework.stereotype.Controller;
- import org.springframework.web.servlet.HandlerExceptionResolver;
- import org.springframework.web.servlet.ModelAndView;
-
- public class golbalException implements HandlerExceptionResolver {
-
- public ModelAndView resolveException(HttpServletRequest request,
- HttpServletResponse response, Object handler, Exception ex) {
- response.setHeader("content-type", "text/html;charset=UTF-8");
- response.setHeader("refresh", "5;url=/shop/index.action");
- zdyException exception =null;
- if(ex instanceof zdyException){
- exception=(zdyException)ex;
- }else{
- exception.setMessage("发生了未知异常");
- }
- ModelAndView modelAndView = new ModelAndView();
- modelAndView.addObject("errorMessage",exception.getMessage()+"系统将在5秒之后跳转到首页......");
- modelAndView.setViewName("error");
- return modelAndView;
- }
-
- }
- package com.shop.exception;
-
- public class zdyException extends Exception{
- private String message;
-
- public zdyException(String message) {
- super();
- this.message = message;
- }
- public String getMessage() {
- return message;
- }
- public void setMessage(String message) {
- this.message = message;
- }
- }
- package com.shop.interceptor;
-
- import java.util.Iterator;
-
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
-
- import org.springframework.web.servlet.HandlerInterceptor;
- import org.springframework.web.servlet.ModelAndView;
-
- public class EncodingInterceptor implements HandlerInterceptor {
-
- @Override
- public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
- Object arg2) throws Exception {
- response.setContentType("text/html;charset=UTF-8");
- /*String method = request.getMethod();
- if (method.equalsIgnoreCase("post")) {
- request.setCharacterEncoding("utf-8");
- } else {
- // new String(request.getParameter("name").getBytes("iso8859-1"),"utf-8");
- Iterator iter = request.getParameterMap().values().iterator();
- while (iter.hasNext()) {
- String[] parames = (String[]) iter.next();
- for (int i = 0; i < parames.length; i++) {
- parames[i] = new String(parames[i].getBytes("iso8859-1"),
- "utf-8");// 此处utf-8与页面编码一样
- }
- }
- }*/
- return true;
- }
-
- @Override
- public void postHandle(HttpServletRequest request, HttpServletResponse response,
- Object arg2, ModelAndView arg3) throws Exception {
- }
-
- @Override
- public void afterCompletion(HttpServletRequest request,
- HttpServletResponse arg1, Object arg2, Exception arg3)
- throws Exception {
- }
- }
- package com.shop.interceptor;
-
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
-
- import org.springframework.stereotype.Controller;
- import org.springframework.web.servlet.HandlerInterceptor;
- import org.springframework.web.servlet.ModelAndView;
-
- import com.shop.po.Adminuser;
-
- @Controller
- public class PrivilageInterceptor implements HandlerInterceptor{
-
- @Override
- public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
- Object object) throws Exception {
- String uri = request.getRequestURI();
- if(uri.indexOf("admin.action")>=0){
- return true;
- }
- Adminuser adminuserLogin = (Adminuser) request.getSession().getAttribute("adminuserLogin");
- if(adminuserLogin!=null){
- return true ;
- }
- request.getRequestDispatcher("/WEB-INF/jsp/admin/index.jsp").forward(request, response);
- return true;
- }
-
- @Override
- public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
- Object arg2, ModelAndView arg3) throws Exception {
- }
-
- @Override
- public void afterCompletion(HttpServletRequest arg0,
- HttpServletResponse arg1, Object arg2, Exception arg3)
- throws Exception {
- }
- }
- package com.shop.Utils;
-
- import java.util.Properties;
-
- import javax.mail.Authenticator;
- import javax.mail.Message;
- import javax.mail.MessagingException;
- import javax.mail.PasswordAuthentication;
- import javax.mail.Session;
- import javax.mail.Transport;
- import javax.mail.internet.AddressException;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- import javax.mail.internet.MimeMessage.RecipientType;
-
- public class MailUtils {
- // email是邮箱地址 emailMsg是发送给邮箱的内容
- public static void sendMail(String email, String emailMsg)
- throws AddressException, MessagingException {
- // 1.创建一个程序与邮件服务器会话对象 Session
- Properties props = new Properties();
- props.setProperty("mail.host", "localhost");
- // 创建验证器
- Authenticator auth = new Authenticator() {
- public PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication("service@shop.com", "111");
- }
- };
- Session session = Session.getInstance(props, auth);
- Message message = new MimeMessage(session);
-
- message.setFrom(new InternetAddress("service@shop.com")); // 设置发送者
-
- message.setRecipient(RecipientType.TO, new InternetAddress(email)); // 设置发送方式与接收者
-
- message.setSubject("用户激活");
- message.setContent(emailMsg, "text/html;charset=utf-8");
- Transport.send(message);
- }
- }
- package com.shop.Utils;
-
- import java.util.List;
-
- public class PageBean
{ - private int page;//第几页
- private int totlePage;//一共多少页
- private int limitPage;//每页多少个
- private List
list;//目标集合 - public int getPage() {
- return page;
- }
- public void setPage(int page) {
- this.page = page;
- }
- public int getTotlePage() {
- return totlePage;
- }
- public void setTotlePage(int totlePage) {
- this.totlePage = totlePage;
- }
- public int getLimitPage() {
- return limitPage;
- }
- public void setLimitPage(int limitPage) {
- this.limitPage = limitPage;
- }
- public List
getList() { - return list;
- }
- public void setList(List
list) { - this.list = list;
- }
- public String toString() {
- return "PageBean [page=" + page + ", totlePage=" + totlePage
- + ", limitPage=" + limitPage + ", list=" + list + "]";
- }
- }
- package com.shop.Utils;
-
- import java.util.UUID;
-
- public class UUIDUtiils {
- public static String getUUID(){
- return UUID.randomUUID().toString();
- }
- }
如果也想学习本系统,下面领取。关注并回复:164ssm