Java项目:基于Servlet+Mybatis+Layui的CRM客户关系管理系统

作者主页:夜未央5788

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

文末获取源码

功能介绍

该项目未使用spring框架,实现了用户登录,权限控制,数据统计,以及市场活动、线索、客户、联系人、交易管理的CRUD,使用Proxy实现Service层的动态代理,实现DAO层事务控制,有助于深入理解web项目。管理员还包含系统设置:用户管理、角色管理、权限管理;其中角色管理可以设置总经理、副总经理、销售经理、综合事务等角色的权限菜单。

环境需要

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.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目 
6.数据库:MySql 5.7版本;

技术栈

1. 后端:Servlet+Mybatis

2. 前端:Layui+jquery+echarts+JSP

使用说明

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

若为maven项目,导入成功后请执行maven clean;maven install命令,下载所需jar包;

2. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
3. 将项目中db.properties配置文件中的数据库配置改为自己的配置
4. 配置tomcat,然后运行项目,输入localhost:8080/xxx 登录
5. 管理员账户:admin  密码:123456
普通员工账户:zs  密码:123

运行截图

Java项目:基于Servlet+Mybatis+Layui的CRM客户关系管理系统_第1张图片

Java项目:基于Servlet+Mybatis+Layui的CRM客户关系管理系统_第2张图片 

Java项目:基于Servlet+Mybatis+Layui的CRM客户关系管理系统_第3张图片 

Java项目:基于Servlet+Mybatis+Layui的CRM客户关系管理系统_第4张图片 

Java项目:基于Servlet+Mybatis+Layui的CRM客户关系管理系统_第5张图片 

Java项目:基于Servlet+Mybatis+Layui的CRM客户关系管理系统_第6张图片 

Java项目:基于Servlet+Mybatis+Layui的CRM客户关系管理系统_第7张图片 

 

相关代码 

ActivityController

package com.crsbg.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.crsbg.entity.Activity;
import com.crsbg.entity.PageVO;
import com.crsbg.entity.User;
import com.crsbg.service.ActivityService;
import com.crsbg.service.impl.ActivityServiceImpl;
import com.crsbg.utils.JSONUtil;
import com.crsbg.utils.ServiceFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ActivityController extends HttpServlet {
    private ActivityService activityService = null;
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String path = request.getServletPath();
        if("/controller/getActivity".equals(path)){
           getActivity(request,response);
        }else if("/controller/createActivity".equals(path)){
            createActivity(request,response);
        }else if("/controller/updateActivity".equals(path)){
            updateActivity(request,response);
        }else if("/controller/deleteActivity".equals(path)){
            deleteActivity(request,response);
        }else if("/controller/deleteActivities".equals(path)){
            deleteActivities(request,response);
        }else if("/controller/getActivityByCid".equals(path)){
            getActivityByCid(request,response);
        }else if("/controller/getActivityByName".equals(path)){
            getActivityByName(request,response);
        }else if("/controller/getActivityByName2".equals(path)){
            getActivityByName2(request,response);
        }else if("/controller/getActivityByConid".equals(path)){
            getActivityByConid(request,response);
        }else if("/controller/getActivityByName3".equals(path)){
            getActivityByName3(request,response);
        }
    }

    private void getActivityByName3(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入getActivityByName3...");
        String sname = request.getParameter("sname");
        String contactsId = request.getParameter("contactsId");
        Map param = new HashMap<>();
        param.put("name",sname);
        param.put("contactsId",contactsId);
        activityService = (ActivityService) ServiceFactory.getService(new ActivityServiceImpl());
        List activityList = activityService.getActivityByName3(param);
        Map map = new HashMap<>();
        map.put("code",0);
        map.put("message","请求成功");
        map.put("count",activityList.size());
        map.put("data",activityList);
        JSONUtil.getJSON(response,map);
    }

    private void getActivityByConid(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入获取市场列表getActivityByConid...");
        activityService = (ActivityService) ServiceFactory.getService(new ActivityServiceImpl());
        String contactsId = request.getParameter("contactsId");
        List activityList = activityService.getActivityByConid(contactsId);
        JSONUtil.getJSON(response,activityList);
    }

    private void getActivityByName2(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入getActivityByName2...");
        String sname = request.getParameter("sname");
        activityService = (ActivityService) ServiceFactory.getService(new ActivityServiceImpl());
        List activityList = activityService.getActivityByName2(sname);
        Map map = new HashMap<>();
        map.put("code",0);
        map.put("message","请求成功");
        map.put("count",activityList.size());
        map.put("data",activityList);
        JSONUtil.getJSON(response,map);
    }

    private void getActivityByName(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入getActivityByName...");
        String sname = request.getParameter("sname");
        String clueId = request.getParameter("clueId");
        Map param = new HashMap<>();
        param.put("name",sname);
        param.put("clueId",clueId);
        activityService = (ActivityService) ServiceFactory.getService(new ActivityServiceImpl());
        List activityList = activityService.getActivityByName(param);
        Map map = new HashMap<>();
        map.put("code",0);
        map.put("message","请求成功");
        map.put("count",activityList.size());
        map.put("data",activityList);
        JSONUtil.getJSON(response,map);
    }

    private void getActivityByCid(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入getActivityByCid...");
        activityService = (ActivityService) ServiceFactory.getService(new ActivityServiceImpl());
        String clueId = request.getParameter("clueId");
        List activityList = activityService.getActivityByCid(clueId);
//        Map map = new HashMap<>();
//        map.put("code",0);
//        map.put("message","请求成功");
//        map.put("count",activityList.size());
//        map.put("data",activityList);
        JSONUtil.getJSON(response,activityList);
    }

    private void deleteActivities(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入deleteActivities");
        activityService = (ActivityService) ServiceFactory.getService(new ActivityServiceImpl());
        String[] ids = request.getParameterValues("id");
        boolean flag = activityService.deleteActivities(ids);
        response.getWriter().print(flag);
    }

    private void deleteActivity(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入deleteActivity");
        activityService = (ActivityService) ServiceFactory.getService(new ActivityServiceImpl());
        String id = request.getParameter("id");
        int res = activityService.deleteActivity(id);
        boolean flag = (res==1?true:false);
        response.getWriter().print(flag);
    }

    private void updateActivity(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入updateActivity");
        activityService = (ActivityService) ServiceFactory.getService(new ActivityServiceImpl());
        String id = request.getParameter("id");
        String owner = request.getParameter("owner");
        String name = request.getParameter("name");
        String startDate = request.getParameter("startDate");
        String endDate = request.getParameter("endDate");
        String cost = request.getParameter("cost");
        String description = request.getParameter("description");
        String editTime = DateUtil.now();
        String editBy = ((User)request.getSession().getAttribute("user")).getName();
        Activity activity = new Activity();
        activity.setId(id);
        activity.setOwner(owner);
        activity.setName(name);
        activity.setStartDate(startDate);
        activity.setEndDate(endDate);
        activity.setCost(cost);
        activity.setDescription(description);
        activity.setEditTime(editTime);
        activity.setEditBy(editBy);
        int res = activityService.updateActivity(activity);
        boolean flag = (res==1?true:false);
        response.getWriter().print(flag);
    }


    private void createActivity(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入createActivity");
        activityService = (ActivityService) ServiceFactory.getService(new ActivityServiceImpl());
        String id = IdUtil.simpleUUID();
        String owner = request.getParameter("create-owner");
        String name = request.getParameter("create-name");
        String startDate = request.getParameter("create-startDate");
        String endDate = request.getParameter("create-endDate");
        String cost = request.getParameter("create-cost");
        String description = request.getParameter("create-description");
        String createTime = DateUtil.now();
        String createBy = ((User)request.getSession().getAttribute("user")).getName();
        Activity activity = new Activity();
        activity.setId(id);
        activity.setOwner(owner);
        activity.setName(name);
        activity.setStartDate(startDate);
        activity.setEndDate(endDate);
        activity.setCost(cost);
        activity.setDescription(description);
        activity.setCreateTime(createTime);
        activity.setCreateBy(createBy);
        int res = activityService.createActivity(activity);
        boolean flag = (res==1?true:false);
        response.getWriter().print(flag);
    }

    private void getActivity(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入getActivity");
        activityService = (ActivityService) ServiceFactory.getService(new ActivityServiceImpl());
        String owner = request.getParameter("owner");
        String name = request.getParameter("name");
        String startDate = request.getParameter("startDate");
        String endDate = request.getParameter("endDate");
        int page = Integer.parseInt(request.getParameter("page"));
        int limit = Integer.parseInt(request.getParameter("limit"));
        int pageNumber = (page-1)*limit;
        int pageSize = limit;
        Map data = new HashMap<>();
        data.put("owner",owner);
        data.put("name",name);
        data.put("startDate",startDate);
        data.put("endDate",endDate);
        data.put("pageNumber",pageNumber);
        data.put("pageSize",pageSize);
        PageVO vo = activityService.getActivity(data);
        Map map = new HashMap<>();
        map.put("code",0);
        map.put("message","请求成功");
        map.put("count",vo.getTotal());
        map.put("data",vo.getDatas());

        JSONUtil.getJSON(response,map);
    }

}

ClueController

package com.crsbg.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONObject;
import com.crsbg.entity.Clue;
import com.crsbg.entity.PageVO;
import com.crsbg.entity.Tran;
import com.crsbg.entity.User;
import com.crsbg.service.ClueService;
import com.crsbg.service.impl.ClueServiceImpl;
import com.crsbg.utils.JSONUtil;
import com.crsbg.utils.ServiceFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ClueController extends HttpServlet {
	private ClueService clueService = null;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String path = request.getServletPath();
	   	if("/controller/getClue".equals(path)){
		    getClue(request,response);
        } else if("/controller/addClue".equals(path)){
            addClue(request,response);
        } else if("/controller/detailClue".equals(path)){
            clueDetail(request,response);
        } else if("/controller/removeClueActivity".equals(path)){
            removeClueActivity(request,response);
        } else if("/controller/addClueActivity".equals(path)){
            addClueActivity(request,response);
        } else if("/controller/getClueByIdAndUser".equals(path)){
            getClueByIdAndUser(request,response);
        } else if("/controller/updateClue".equals(path)){
            updateClue(request,response);
        } else if("/controller/deleteClue".equals(path)){
            deleteClue(request,response);
        } else if("/controller/deleteClues".equals(path)){
            deleteClues(request,response);
        } else if("/controller/convert".equals(path)){
            convert(request,response);
        }
	}

    private void convert(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("进入线索转换convert...");
        clueService = (ClueService) ServiceFactory.getService(new ClueServiceImpl());
        String clueId = request.getParameter("clueId");
        String isCreateTran = request.getParameter("isCreateTran");
        String createBy = ((User)request.getSession().getAttribute("user")).getName();
        Tran tran = null;
        if("yes".equals(isCreateTran)){
            String id = IdUtil.simpleUUID();
            String name = request.getParameter("name");
            String money = request.getParameter("money");
            String expectedDate = request.getParameter("expectedDate");
            String stage = request.getParameter("stage");
            String activityId = request.getParameter("activityId");
            String createTime = DateUtil.now();
            tran = new Tran();
            tran.setId(id);
            tran.setName(name);
            tran.setMoney(money);
            tran.setExpectedDate(expectedDate);
            tran.setStage(stage);
            tran.setActivityId(activityId);
            tran.setCreateBy(createBy);
            tran.setCreateTime(createTime);
        }
        boolean flag = clueService.convert(clueId,createBy,tran);
        request.setAttribute("convertRes",flag);
        request.getRequestDispatcher("/pages/clue.jsp").forward(request,response);
    }

    private void deleteClues(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入批量删除线索deleteClues...");
        clueService = (ClueService) ServiceFactory.getService(new ClueServiceImpl());
        String[] ids = request.getParameterValues("id");
        boolean flag = clueService.deleteClues(ids);
        response.getWriter().print(flag);
    }

    private void deleteClue(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入单条删除线索deleteClue...");
        clueService = (ClueService) ServiceFactory.getService(new ClueServiceImpl());
        String id = request.getParameter("id");
        boolean flag = clueService.deleteClue(id);
        response.getWriter().print(flag);
    }

    private void updateClue(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入线索修改updateClue...");
        clueService = (ClueService) ServiceFactory.getService(new ClueServiceImpl());
        String id = request.getParameter("id");
        String fullname = request.getParameter("fullname");
        String appellation = request.getParameter("appellation");
        String owner = request.getParameter("owner");
        String company = request.getParameter("company");
        String job = request.getParameter("job");
        String email = request.getParameter("email");
        String tel = request.getParameter("tel");
        String website = request.getParameter("website");
        String phone = request.getParameter("phone");
        String state = request.getParameter("state");
        String source = request.getParameter("source");
        String editBy = ((User)request.getSession().getAttribute("user")).getName();
        String editTime = DateUtil.now();
        String description = request.getParameter("description");
        String contactSummary = request.getParameter("contactSummary");
        String nextContactDate = request.getParameter("nextContactDate");
        String address = request.getParameter("address");
        Clue clue = new Clue();
        clue.setId(id);
        clue.setFullname(fullname);
        clue.setAppellation(appellation);
        clue.setOwner(owner);
        clue.setCompany(company);
        clue.setJob(job);
        clue.setEmail(email);
        clue.setTel(tel);
        clue.setWebsite(website);
        clue.setPhone(phone);
        clue.setState(state);
        clue.setSource(source);
        clue.setEditBy(editBy);
        clue.setEditTime(editTime);
        clue.setDescription(description);
        clue.setContactSummary(contactSummary);
        clue.setNextContactDate(nextContactDate);
        clue.setAddress(address);
        boolean flag = clueService.updateClue(clue);
        response.getWriter().print(flag);
    }

    private void getClueByIdAndUser(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入查询线索和用户getClueByIdAndUser...");
        String id = request.getParameter("id");
        clueService = (ClueService) ServiceFactory.getService(new ClueServiceImpl());
        Map map = clueService.getClueByIdAndUser(id);
        JSONUtil.getJSON(response, map);
    }

    private void removeClueActivity(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入解除线索和市场活动关系removeClueActivity...");
        String id = request.getParameter("id");
        clueService = (ClueService) ServiceFactory.getService(new ClueServiceImpl());
        boolean flag = clueService.removeClueActivity(id);
        response.getWriter().print(flag);
    }

    private void addClueActivity(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入添加线索和市场活动关系addClueActivity...");
        String clueId = request.getParameter("cid");
        String[] activityIds = request.getParameterValues("aid");
        clueService = (ClueService) ServiceFactory.getService(new ClueServiceImpl());
        boolean flag = clueService.addClueActivity(clueId,activityIds);
        response.getWriter().print(flag);
    }

    private void clueDetail(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        System.out.println("进入查询线索详细信息detailClue...");
        clueService = (ClueService) ServiceFactory.getService(new ClueServiceImpl());
        String id = request.getParameter("id");
        Clue clue = clueService.detailClue(id);
        request.setAttribute("clue",clue);
        request.getRequestDispatcher("/pages/clue-detail.jsp").forward(request,response);
    }

    private void addClue(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入addClue...");
        clueService = (ClueService) ServiceFactory.getService(new ClueServiceImpl());
        String id = IdUtil.simpleUUID();
        String fullname = request.getParameter("fullname");
        String appellation = request.getParameter("appellation");
        String owner = request.getParameter("owner");
        String company = request.getParameter("company");
        String job = request.getParameter("job");
        String email = request.getParameter("email");
        String tel = request.getParameter("tel");
        String website = request.getParameter("website");
        String phone = request.getParameter("phone");
        String state = request.getParameter("state");
        String source = request.getParameter("source");
        String createBy = ((User)request.getSession().getAttribute("user")).getName();
        String createTime = DateUtil.now();
        String description = request.getParameter("description");
        String contactSummary = request.getParameter("contactSummary");
        String nextContactDate = request.getParameter("nextContactDate");
        String address = request.getParameter("address");
        Clue clue = new Clue();
        clue.setId(id);
        clue.setFullname(fullname);
        clue.setAppellation(appellation);
        clue.setOwner(owner);
        clue.setCompany(company);
        clue.setJob(job);
        clue.setEmail(email);
        clue.setTel(tel);
        clue.setWebsite(website);
        clue.setPhone(phone);
        clue.setState(state);
        clue.setSource(source);
        clue.setCreateBy(createBy);
        clue.setCreateTime(createTime);
        clue.setDescription(description);
        clue.setContactSummary(contactSummary);
        clue.setNextContactDate(nextContactDate);
        clue.setAddress(address);
        boolean flag = clueService.addClue(clue);
        response.getWriter().print(flag);
    }

    private void getClue(HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("进入getClue...");
        String owner = request.getParameter("owner");
        String fullname = request.getParameter("fullname");
        String company = request.getParameter("company");
        int page = Integer.parseInt(request.getParameter("page"));
        int limit = Integer.parseInt(request.getParameter("limit"));
        int pageNumber = (page-1)*limit;
        int pageSize = limit;
        clueService = (ClueService)ServiceFactory.getService(new ClueServiceImpl());
        Map param = new HashMap<>();
        param.put("owner",owner);
        param.put("fullname",fullname);
        param.put("company",company);
        param.put("pageNumber",pageNumber);
        param.put("pageSize",pageSize);
        PageVO vo = clueService.getClue(param);
        Map map = new HashMap<>();
        map.put("code",0);
        map.put("message","请求成功");
        map.put("count",vo.getTotal());
        map.put("data",vo.getDatas());
        JSONUtil.getJSON(response,map);
    }


}

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

你可能感兴趣的:(JSP,java,mybatis,servlet)